I''ve been away from rails for a while but now wanna get back into it and I guess my rails foo has got rusty. I''ve been wrestling with this simple! problem for the weekend and I can''t fix it - driving me nuts. Real cry for help. I have a Course model which contains price_per_week. I''d like one page where a user selects a course and a duration and then submits this, the next page will look up the Course price and multiply by the duration and display a quote. EASY huh, not for me this weekend ! All I need for now to get back on track is just to get the basics, how do I pass the bl*^(*^dy Course through to the price screen.. Please see the code below. I''d be most grateful if someone can point me in the right direction.. I recognise that the I am not passing any params at the moment from this... <%= link_to ''Get a Price!'', :action => ''price'', :id => @course %> <--- this is wrong ? But how do I do it ? I''ll be happy just to get the Course name displayed for now, come back to the pricing later. bb ------ VIEW <html> <head> <title>Ajax Demo</title> <%= javascript_include_tag "prototype" %> </head> <body> <%= collection_select(:course, :id, @courses, :id, :name, options ={:prompt => "-Select a payment"}, :class =>"course") %> <br> <%= link_to ''Get a Price!'', :action => ''price'', :id => @course %> <--- this is wrong ? <br> <%= link_to ''Reset'', :action => ''index'' %> </body> </html> ======= controller class InvoiceController < ApplicationController def index @enquiry = Enquiry.new @courses = Course.active_courses @courses = Course.active_courses render :layout => "welcome" end def price @time = Time.now render :layout => "welcome" # @course = Course.find(:id) @selected_course = params[course][id] end end ====== Price view <%= @time %><br> <hr> Price Below<br> <hr> <br> <%= @selected_course.name %> bla bla bla to come... -- 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 -~----------~----~----~----~------~----~------~--~---
On Aug 24, 10:04 am, bingo bob <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I''ve been away from rails for a while but now wanna get back into it and > I guess my rails foo has got rusty. I''ve been wrestling with this > simple! problem for the weekend and I can''t fix it - driving me nuts. > Real cry for help. > > I have a Course model which contains price_per_week. > > I''d like one page where a user selects a course and a duration and then > submits this, the next page will look up the Course price and multiply > by the duration and display a quote. EASY huh, not for me this weekend ! > > All I need for now to get back on track is just to get the basics, how > do I pass the bl*^(*^dy Course through to the price screen.. Please see > the code below. I''d be most grateful if someone can point me in the > right direction..You''ve already passed the first screen''s state to the next screen. In the next screen, you simply needs to put hidden fields in the form in order to preserve the previous state, so that the POST handler will have all the data. --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I don''t get you. Any chance of an example? I''m also not passing any params. ? Hongli Lai wrote:> On Aug 24, 10:04�am, bingo bob <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> >> All I need for now to get back on track is just to get the basics, how >> do I pass the bl*^(*^dy Course through to the price screen.. Please see >> the code below. I''d be most grateful if someone can point me in the >> right direction.. > > You''ve already passed the first screen''s state to the next screen. In > the next screen, you simply needs to put hidden fields in the form in > order to preserve the previous state, so that the POST handler will > have all the data.-- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Aug 24, 10:30 am, bingo bob <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I don''t get you. Any chance of an example? > > I''m also not passing any params. ?You''re already passing the course (or at least its id). What more do you need ? Fred> > Hongli Lai wrote: > > On Aug 24, 10:04 am, bingo bob <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > > >> All I need for now to get back on track is just to get the basics, how > >> do I pass the bl*^(*^dy Course through to the price screen.. Please see > >> the code below. I''d be most grateful if someone can point me in the > >> right direction.. > > > You''ve already passed the first screen''s state to the next screen. In > > the next screen, you simply needs to put hidden fields in the form in > > order to preserve the previous state, so that the POST handler will > > have all the data. > > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On Aug 24, 10:30�am, bingo bob <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> I don''t get you. Any chance of an example? >> >> I''m also not passing any params. ? > > You''re already passing the course (or at least its id). What more do > you need ? > > FredThat''s not working. -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Aug 24, 10:46 am, bingo bob <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Frederick Cheung wrote: > > On Aug 24, 10:30 am, bingo bob <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > >> I don''t get you. Any chance of an example? > > >> I''m also not passing any params. ? > > > You''re already passing the course (or at least its id). What more do > > you need ? > > > Fred > > That''s not working.Well what you should be doing in your price action @selected_course = Course.find params[:id] to turn that id back into an instance of course Fred> -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On Aug 24, 10:46�am, bingo bob <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> > Fred >> >> That''s not working. > > Well what you should be doing in your price action > > @selected_course = Course.find params[:id] > > to turn that id back into an instance of course > > FredRight. Ok. I see that now, thanks. However what I''m saying is that as it stands the ID is not being passed? -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Aug 24, 12:20 pm, bingo bob <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Right. Ok. I see that now, thanks. > > However what I''m saying is that as it stands the ID is not being passed?You have: @selected_course = params[course][id] Should be: @selected_course = params[:course][:id] Otherwise you will be accessing the ''params'' hash with the return value of the ''course'' function as key, and you will be accessing the returned hash with the return value of the ''id'' function as key. --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Should be: > @selected_course = params[:course][:id]Sorry I pressed Send too quickly. I meant: @selected_course = Course.find_by_id(params[:course][:id]) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hongli Lai wrote:>> Should be: >> @selected_course = params[:course][:id > > Sorry I pressed Send too quickly. I meant: > > @selected_course = Course.find_by_id(params[:course][:id])I am looking at the link_to "get a price" I don''t think it''s actually passing the id of the course. You think that part (the linkto) is correct then? -- 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 -~----------~----~----~----~------~----~------~--~---
bingo bob wrote:> Hongli Lai wrote: >>> Should be: >>> @selected_course = params[:course][:id >> >> Sorry I pressed Send too quickly. I meant: >> >> @selected_course = Course.find_by_id(params[:course][:id]) > > I am looking at the link_to "get a price" > > I don''t think it''s actually passing the id of the course. > You think that part (the linkto) is correct then?To be clear, this is the error I see when the button is clicked... Processing InvoiceController#price (for 127.0.0.1 at 2008-08-24 12:34:02) [GET] Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%0ASGFzaHsABjoKQHVzZWR7AA%3D%3D--09cd542da5f8d4e176562c6e4277422bc3d60982 Parameters: {"action"=>"price", "id"=>"course", "controller"=>"invoice"} Rendering template within layouts/welcome Rendering invoice/price ActionView::TemplateError (You have a nil object when you didn''t expect it! The error occurred while evaluating nil.name) on line #12 of invoice/price.html.erb: 9: 10: <br> 11: 12: <%= @selected_course.name %> 13: -------------- Parameters: {"action"=>"price", "id"=>"course", "controller"=>"invoice"} <-- this is wrong I believe I should see the ID in here? -- 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 -~----------~----~----~----~------~----~------~--~---
On 24 Aug 2008, at 12:35, bingo bob <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > bingo bob wrote: >> Hongli Lai wrote: >>>> Should be: >>>> @selected_course = params[:course][:id >>> >>> Sorry I pressed Send too quickly. I meant: >>> >>> @selected_course = Course.find_by_id(params[:course][:id]) >> >> I am looking at the link_to "get a price" >> >> I don''t think it''s actually passing the id of the course. >> You think that part (the linkto) is correct then? > > > > To be clear, this is the error I see when the button is clicked... >All of this was based on the assumption that @course was an instance of course. Is it really ? What you are getting suggests it isn''t ( if so what is it) Fred> Processing InvoiceController#price (for 127.0.0.1 at 2008-08-24 > 12:34:02) [GET] > Session ID: > BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo > %0ASGFzaHsABjoKQHVzZWR7AA%3D > %3D--09cd542da5f8d4e176562c6e4277422bc3d60982 > Parameters: {"action"=>"price", "id"=>"course", > "controller"=>"invoice"} > Rendering template within layouts/welcome > Rendering invoice/price > > > ActionView::TemplateError (You have a nil object when you didn''t > expect > it! > The error occurred while evaluating nil.name) on line #12 of > invoice/price.html.erb: > 9: > 10: <br> > 11: > 12: <%= @selected_course.name %> > 13: > > > -------------- > > > Parameters: {"action"=>"price", "id"=>"course", > "controller"=>"invoice"} > <-- this is wrong I believe I should see the ID in here? > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 24 Aug 2008, at 12:35, bingo bob <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > >>> I am looking at the link_to "get a price" >>> >>> I don''t think it''s actually passing the id of the course. >>> You think that part (the linkto) is correct then? >> >> >> >> To be clear, this is the error I see when the button is clicked... >> > > All of this was based on the assumption that @course was an instance > of course. Is it really ? What you are getting suggests it isn''t ( if > so what is it) > > FredThe lines of code below are meant to get me the params I need? Is the collection select maybe wrong? or the link_to, or maybe both? either way I dont see the params being passed by the link_to. <%= collection_select(:course, :id, @courses, :id, :name, options ={:prompt => "-Select a payment"}, :class =>"course") %> <br> <%= link_to ''Get a Price!'', :action => ''price'', :id => @course %> -- 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 -~----------~----~----~----~------~----~------~--~---
On 24 Aug 2008, at 12:57, bingo bob <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Frederick Cheung wrote: >> On 24 Aug 2008, at 12:35, bingo bob <rails-mailing-list@andreas- >> s.net> >> wrote: >> >>>> I am looking at the link_to "get a price" >>>> >>>> I don''t think it''s actually passing the id of the course. >>>> You think that part (the linkto) is correct then? >>> >>> >>> >>> To be clear, this is the error I see when the button is clicked... >>> >> >> All of this was based on the assumption that @course was an instance >> of course. Is it really ? What you are getting suggests it isn''t ( if >> so what is it) >> >> Fred > > The lines of code below are meant to get me the params I need? > Is the collection select maybe wrong? or the link_to, or maybe both? >What is wrong is that you expect a link to submit parameters from a form element. That''s not what links do. You need a form. Fred> either way I dont see the params being passed by the link_to. > > <%= collection_select(:course, :id, @courses, :id, :name, options > ={:prompt => "-Select a payment"}, :class =>"course") %> > > <br> > > <%= link_to ''Get a Price!'', :action => ''price'', :id => @course %> > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Like this? <% form_tag :action => ''price'' do %> <%= collection_select(:course, :id, @courses, :id, :name, options ={:prompt => "-Select a payment"}, :class =>"course") %> <%= submit_tag "Price" %> <% end %> -- 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 -~----------~----~----~----~------~----~------~--~---