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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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? On 2/9/07, Daniel Owen van Dommelen <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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 > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Chris Hall 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?? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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"=>"test5-J0of1frlU80@public.gmane.org", "password_confirmation"=>"1234", "lastname"=>"12345", "firstname"=>"12345", "mobile"=>"0612345678", "date_of_birth"=>"01-01-2001", "telephone"=>"02012345678", "password"=>"1234", "email"=>"test5-J0of1frlU80@public.gmane.org"}, "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... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---