Got Josh?
2011-Jan-18 18:52 UTC
Rails way of constructing an url with post parameters of a form
I would like to do that''s the best way of actually accomplishing the following on Rails. I have a "Booking Form" with 5 fields (Property, Amount of Children, Amount of Adults and 2 Dates - Departure and Arrival) based on these fields, I need to construct an URL and redirect the user to this url. Now, I have 2 questions. 1) How i catch the POST parameters in the controller, because I''m mapping the form to an action like this: <% form_tag(:action => "booking") do %> and routing it to a controller action like this: (Pages Controller, Booking Action) match ''pages/booking'' => ''pages#booking'' 2) Is this the Rails way of actually accomplishing such thing? I did it this way in PHP in the past, but now I have the need of actually doing it in Rails, could you Rails Gurus inspire me ? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Jan-18 21:36 UTC
Re: Rails way of constructing an url with post parameters of a form
On 18 Jan 2011, at 18:52, "Got Josh?" <josue.abreu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I would like to do that''s the best way of actually accomplishing the > following on Rails. > > I have a "Booking Form" with 5 fields (Property, Amount of Children, > Amount of Adults and 2 Dates - Departure and Arrival) based on these > fields, I need to construct an URL and redirect the user to this url. > Now, I have 2 questions. > > 1) How i catch the POST parameters in the controller, because I''m > mapping the form to an action like this: >They''ll be in params. You might make your life slightly easier if you name your parameters foo[p1], foo[p2] etc, because then all your parameters are in params[:foo]. Hash#to_query turns a hash back into a query string.> <% form_tag(:action => "booking") do %> > > and routing it to a controller action like this: (Pages Controller, > Booking Action) > > match ''pages/booking'' => ''pages#booking'' > > 2) Is this the Rails way of actually accomplishing such thing? >I don''t quite understand what you are doing. What''s the point of the intermediate action? Fred> I did it this way in PHP in the past, but now I have the need of > actually doing it in Rails, could you Rails Gurus inspire me ? > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Got Josh?
2011-Jan-18 21:47 UTC
Re: Rails way of constructing an url with post parameters of a form
I already did it, but perhaps you can point me in a better way. I made a class called Booking Information: https://gist.github.com/785209 Where I''ll store the post parameters of my interest like this: @booking_info = BookingInformation.new( params[:properties], params[:children], params[:adults], params[:checkin], params[:checkout], params[:locale] ) after that I''ll just redirect the user to the proper URL with redirect_to(@booking_info.output_url) The reason why I''m doing this is because I have a form where based on the user input of a given property, date-range and amount of persons, must redirect to a URL constructed with the given parameters (The code is the gist), That''s the point of the intermediate action (More specifically based on the property an chain and propertyID must be assigned) On Jan 18, 5:36 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 18 Jan 2011, at 18:52, "Got Josh?" <josue.ab...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I would like to do that''s the best way of actually accomplishing the > > following on Rails. > > > I have a "Booking Form" with 5 fields (Property, Amount of Children, > > Amount of Adults and 2 Dates - Departure and Arrival) based on these > > fields, I need to construct an URL and redirect the user to this url. > > Now, I have 2 questions. > > > 1) How i catch the POST parameters in the controller, because I''m > > mapping the form to an action like this: > > They''ll be in params. You might make your life slightly easier if you name your parameters foo[p1], foo[p2] etc, because then all your parameters are in params[:foo]. Hash#to_query turns a hash back into a query string. > > > <% form_tag(:action => "booking") do %> > > > and routing it to a controller action like this: (Pages Controller, > > Booking Action) > > > match ''pages/booking'' => ''pages#booking'' > > > 2) Is this the Rails way of actually accomplishing such thing? > > I don''t quite understand what you are doing. What''s the point of the intermediate action? > > Fred > > > > > > > > > I did it this way in PHP in the past, but now I have the need of > > actually doing it in Rails, could you Rails Gurus inspire me ? > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Got Josh?
2011-Jan-19 16:54 UTC
Re: Rails way of constructing an url with post parameters of a form
Any help anyone? :( On Jan 18, 5:47 pm, "Got Josh?" <josue.ab...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I already did it, but perhaps you can point me in a better way. > > I made a class called Booking Information:https://gist.github.com/785209 > > Where I''ll store the post parameters of my interest like this: > > @booking_info = BookingInformation.new( > params[:properties], > params[:children], > params[:adults], > params[:checkin], > params[:checkout], > params[:locale] > ) > > after that I''ll just redirect the user to the proper URL with > redirect_to(@booking_info.output_url) > > The reason why I''m doing this is because I have a form where based on > the user input of a given property, date-range and amount of persons, > must redirect to a URL constructed with the given parameters (The code > is the gist), > > That''s the point of the intermediate action (More specifically based > on the property an chain and propertyID must be assigned) > > On Jan 18, 5:36 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > > > > > On 18 Jan 2011, at 18:52, "Got Josh?" <josue.ab...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I would like to do that''s the best way of actually accomplishing the > > > following on Rails. > > > > I have a "Booking Form" with 5 fields (Property, Amount of Children, > > > Amount of Adults and 2 Dates - Departure and Arrival) based on these > > > fields, I need to construct an URL and redirect the user to this url. > > > Now, I have 2 questions. > > > > 1) How i catch the POST parameters in the controller, because I''m > > > mapping the form to an action like this: > > > They''ll be in params. You might make your life slightly easier if you name your parameters foo[p1], foo[p2] etc, because then all your parameters are in params[:foo]. Hash#to_query turns a hash back into a query string. > > > > <% form_tag(:action => "booking") do %> > > > > and routing it to a controller action like this: (Pages Controller, > > > Booking Action) > > > > match ''pages/booking'' => ''pages#booking'' > > > > 2) Is this the Rails way of actually accomplishing such thing? > > > I don''t quite understand what you are doing. What''s the point of the intermediate action? > > > Fred > > > > I did it this way in PHP in the past, but now I have the need of > > > actually doing it in Rails, could you Rails Gurus inspire me ? > > > > -- > > > 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-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.