Params in controllers


#1

Hey people,

Back with another simple question…

How can I access a paramater inside my controller which is provided
through the url. I am doing the following inside my view:

<%= link_to “signup”, :controller => “account”, :action => “signup”,
:type => “candidate” %>

iside my account controller I have the following:

def signup
if params[:type] == “candidate”
@candidate = Candidate.new(params[:candidate])
return unless request.post?
@candidate.save!
self.current_candidate = @candidate
elsif params[:type] == “landlord”
@landlord = Landlord.new(params[:landlord])
return unless request.post?
@landlord.save!
self.current_landlord = @landlord
end
redirect_back_or_default(:controller => ‘home’, :action => ‘index’)
rescue ActiveRecord::RecordInvalid
render :action => ‘signup’
end

It doesn’t want to access the params[:type] variable, but it also does
not generate an error, possibly because the actual code is not false.

Many thanks,

  • Danny

#2

when you mouse over the link, do you see the parameter on the end of the
URL?

http://www.mysite.com/account/signup?type=candidate

or if using a route like ‘/account/signup/:type’

http://www.mysite.com/account/signup/candidate

do you see it in the source from the browser?

watching your development.log, do you see the parameter when the link
is clicked?


#3

Chris H. wrote:

when you mouse over the link, do you see the parameter on the end of the
URL?

http://www.mysite.com/account/signup?type=candidate

or if using a route like ‘/account/signup/:type’

http://www.mysite.com/account/signup/candidate

do you see it in the source from the browser?

watching your development.log, do you see the parameter when the link
is clicked?

yeah I do see the parameter in the url.

http://127.0.0.1:3000/account/signup?type=candidate

But is the parameter still accessible after I submit the form which has
the action signup in the account controller??


#4

Processing AccountController#signup (for 127.0.0.1 at 2007-02-09
14:57:10) [POST]
Session ID: 68d0c5bdc1fc8688e10718fcd2c235fb
Parameters: {“commit”=>“Aanmelden”,
“candidate”=>{“email_confirmation”=>“removed_email_address@domain.invalid”,
“password_confirmation”=>“1234”, “lastname”=>“12345”,
“firstname”=>“12345”, “mobile”=>“0612345678”,
“date_of_birth”=>“01-01-2001”, “telephone”=>“02012345678”,
“password”=>“1234”, “email”=>“removed_email_address@domain.invalid”}, “action”=>“signup”,
“controller”=>“account”}
Redirected to http://127.0.0.1:3000/
Completed in 0.00194 (515 reqs/sec) | DB: 0.00000 (0%) | 302 Found
[http://127.0.0.1/account/signup]

see it doesn’t show the :type parameter, but is the following
possible…

instead of if/elsing the :type parameter I check if the :candidate or
the :landlord array exists… Going to try that now…