James allan To
2011-Feb-21 03:34 UTC
Newb: Order page, multiple view single model question
Hi I would just like to ask if someone can point me to the right direction. I have an order page which will need to be split into 3 views before saving say in controller: def new @order = Order.new end def process_new @order = Order.new(params[:order]) #do validation for new # redirect to no_of_attendees end def no_of_attendees @order = Order.new(params[:order]) end def process_no_of_attendees @order = Order.new(params[:order]) #do validation #redirect to save page end Question: Is there aright way of doing this (carry params values between views) or should I just place the data from new in session as we move to forward to the third page create a hash from session and save in model? Thanks, James P>S. Rails 2.3.10 -- 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-/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.
Srikanth Jeeva
2011-Feb-21 06:45 UTC
Re: Newb: Order page, multiple view single model question
I''m not sure if this is the right way, wht i did in the same case was, converting it to JSON and pass the params. I didn''t like to store a large params in session and so i did like this. def process_new @order = Order.new(params[:order]) end In the view.. <%= hidden_field_tag "order_json", @order.to_json %> back in controller: JSON.parse(params[:order_json]) Thanks, Srikanth J http://srikanthjeeva.blogspot.com/ -- 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-/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.
Jim Ruther Nill
2011-Feb-21 07:22 UTC
Re: Re: Newb: Order page, multiple view single model question
I think saving it in a session is the best way. as long as you don''t store an object in the session, it''s fine. On Mon, Feb 21, 2011 at 2:45 PM, Srikanth Jeeva <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> I''m not sure if this is the right way, wht i did in the same case was, > converting it to JSON and pass the params. I didn''t like to store a > large params in session and so i did like this. > > > def process_new > @order = Order.new(params[:order]) > end > > In the view.. > <%= hidden_field_tag "order_json", @order.to_json %> > > back in controller: > > JSON.parse(params[:order_json]) > > Thanks, > Srikanth J > http://srikanthjeeva.blogspot.com/ > > -- > 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-/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. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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-/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.
On 21 February 2011 03:34, James allan To <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi I would just like to ask if someone can point me to the right > direction. I have an order page which will need to be split into 3 views > before saving say in controller: > > def new > @order = Order.new > end > > def process_new > @order = Order.new(params[:order]) > #do validation for new > # redirect to no_of_attendees > end > > def no_of_attendees > @order = Order.new(params[:order]) > end > > def process_no_of_attendees > @order = Order.new(params[:order]) > #do validation > #redirect to save page > end > > Question: Is there aright way of doing this (carry params values between > views) or should I just place the data from new in session as we move to > forward to the third page create a hash from session and save in model?If all you are passing back each time is the latest data for the order, so you can do Order.new(params[:order]) as you have shown, then there is no reason to complicate things by using the session. You might like to consider whether the controller (and maybe the view) would be simplified by combining the actions (and maybe views) and passing up and back a phase value to indicate which phase of the operation is current. Make sure you do the validation in the model so that at each action you are just asking the model to validate itself, rather than putting validation code in the controller. Colin -- 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.
Jim Ruther Nill
2011-Feb-21 07:56 UTC
Re: Newb: Order page, multiple view single model question
On Mon, Feb 21, 2011 at 3:38 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 21 February 2011 03:34, James allan To <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > Hi I would just like to ask if someone can point me to the right > > direction. I have an order page which will need to be split into 3 views > > before saving say in controller: > > > > def new > > @order = Order.new > > end > > > > def process_new > > @order = Order.new(params[:order]) > > #do validation for new > > # redirect to no_of_attendees > > end > > > > def no_of_attendees > > @order = Order.new(params[:order]) > > end > > > > def process_no_of_attendees > > @order = Order.new(params[:order]) > > #do validation > > #redirect to save page > > end > > > > Question: Is there aright way of doing this (carry params values between > > views) or should I just place the data from new in session as we move to > > forward to the third page create a hash from session and save in model? > > If all you are passing back each time is the latest data for the > order, so you can do Order.new(params[:order]) as you have shown, then > there is no reason to complicate things by using the session. > >this is fine as long as you place the attributes in the previous step in a hidden field so it will not be lost when you submit the form.> You might like to consider whether the controller (and maybe the view) > would be simplified by combining the actions (and maybe views) and > passing up and back a phase value to indicate which phase of the > operation is current. > > Make sure you do the validation in the model so that at each action > you are just asking the model to validate itself, rather than putting > validation code in the controller. > > Colin > > -- > 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. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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-/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.
On 21 February 2011 07:56, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Mon, Feb 21, 2011 at 3:38 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> >> On 21 February 2011 03:34, James allan To <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> > Hi I would just like to ask if someone can point me to the right >> > direction. I have an order page which will need to be split into 3 views >> > before saving say in controller: >> > >> > def new >> > @order = Order.new >> > end >> > >> > def process_new >> > @order = Order.new(params[:order]) >> > #do validation for new >> > # redirect to no_of_attendees >> > end >> > >> > def no_of_attendees >> > @order = Order.new(params[:order]) >> > end >> > >> > def process_no_of_attendees >> > @order = Order.new(params[:order]) >> > #do validation >> > #redirect to save page >> > end >> > >> > Question: Is there aright way of doing this (carry params values between >> > views) or should I just place the data from new in session as we move to >> > forward to the third page create a hash from session and save in model? >> >> If all you are passing back each time is the latest data for the >> order, so you can do Order.new(params[:order]) as you have shown, then >> there is no reason to complicate things by using the session. >> > > this is fine as long as you place the attributes in the previous step in a > hidden field so it will not be lost > when you submit the form.It appears from the OP that even this is not necessary, as all the required data is in params[:order].> >> >> You might like to consider whether the controller (and maybe the view) >> would be simplified by combining the actions (and maybe views) and >> passing up and back a phase value to indicate which phase of the >> operation is current.To do this would require a hidden field as you have pointed out. Colin -- 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.
Jim Ruther Nill
2011-Feb-21 08:50 UTC
Re: Newb: Order page, multiple view single model question
On Mon, Feb 21, 2011 at 4:34 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 21 February 2011 07:56, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > On Mon, Feb 21, 2011 at 3:38 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > wrote: > >> > >> On 21 February 2011 03:34, James allan To <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> > Hi I would just like to ask if someone can point me to the right > >> > direction. I have an order page which will need to be split into 3 > views > >> > before saving say in controller: > >> > > >> > def new > >> > @order = Order.new > >> > end > >> > > >> > def process_new > >> > @order = Order.new(params[:order]) > >> > #do validation for new > >> > # redirect to no_of_attendees > >> > end > >> > > >> > def no_of_attendees > >> > @order = Order.new(params[:order]) > >> > end > >> > > >> > def process_no_of_attendees > >> > @order = Order.new(params[:order]) > >> > #do validation > >> > #redirect to save page > >> > end > >> > > >> > Question: Is there aright way of doing this (carry params values > between > >> > views) or should I just place the data from new in session as we move > to > >> > forward to the third page create a hash from session and save in > model? > >> > >> If all you are passing back each time is the latest data for the > >> order, so you can do Order.new(params[:order]) as you have shown, then > >> there is no reason to complicate things by using the session. > >> > > > > this is fine as long as you place the attributes in the previous step in > a > > hidden field so it will not be lost > > when you submit the form. > > It appears from the OP that even this is not necessary, as all the > required data is in params[:order]. > >even if all the required data is in params[:order], he still needs to set the attributes filled up in the last step as hidden fields. for example (let''s use the OP''s actions) STEP1. #new action this step asks for order''s name, so we''d have params[:order] = {:name => name} available for next step. STEP2 #process_new action this step asks for order''s no_of_attendees. so we''d have params[:order] {:no_of_attendees => no_of_attendees} available for next step. STEP3 #process_no_of_attendees in this action, we already lost the name attribute for order since we didn''t add a hidden field for this attribute. so eventhough we use params[:order] in all the actions, it''s still needed to add hidden_field tags for attributes filled up in the previous actions.> > > >> > >> You might like to consider whether the controller (and maybe the view) > >> would be simplified by combining the actions (and maybe views) and > >> passing up and back a phase value to indicate which phase of the > >> operation is current. > > To do this would require a hidden field as you have pointed out. > > Colin > > -- > 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. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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-/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.
On 21 February 2011 08:50, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Mon, Feb 21, 2011 at 4:34 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> >> On 21 February 2011 07:56, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > >> > >> > On Mon, Feb 21, 2011 at 3:38 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> >> > wrote: >> >> >> >> On 21 February 2011 03:34, James allan To <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> >> > Hi I would just like to ask if someone can point me to the right >> >> > direction. I have an order page which will need to be split into 3 >> >> > views >> >> > before saving say in controller: >> >> > >> >> > def new >> >> > @order = Order.new >> >> > end >> >> > >> >> > def process_new >> >> > @order = Order.new(params[:order]) >> >> > #do validation for new >> >> > # redirect to no_of_attendees >> >> > end >> >> > >> >> > def no_of_attendees >> >> > @order = Order.new(params[:order]) >> >> > end >> >> > >> >> > def process_no_of_attendees >> >> > @order = Order.new(params[:order]) >> >> > #do validation >> >> > #redirect to save page >> >> > end >> >> > >> >> > Question: Is there aright way of doing this (carry params values >> >> > between >> >> > views) or should I just place the data from new in session as we move >> >> > to >> >> > forward to the third page create a hash from session and save in >> >> > model? >> >> >> >> If all you are passing back each time is the latest data for the >> >> order, so you can do Order.new(params[:order]) as you have shown, then >> >> there is no reason to complicate things by using the session. >> >> >> > >> > this is fine as long as you place the attributes in the previous step in >> > a >> > hidden field so it will not be lost >> > when you submit the form. >> >> It appears from the OP that even this is not necessary, as all the >> required data is in params[:order]. >> > > even if all the required data is in params[:order], he still needs to set > the attributes > filled up in the last step as hidden fields. > for example (let''s use the OP''s actions) > STEP1. #new action > this step asks for order''s name, so we''d have params[:order] = {:name => > name} available for next step. > STEP2 #process_new action > this step asks for order''s no_of_attendees. so we''d have params[:order] > {:no_of_attendees => no_of_attendees} available for next step. > STEP3 #process_no_of_attendees > in this action, we already lost the name attribute for order since we didn''t > add a hidden field for this attribute. > so eventhough we use params[:order] in all the actions, it''s still needed to > add hidden_field tags for attributes > filled up in the previous actions.I see what you mean now, I was assuming the previous data would still be visible, but I take your point, it may not be. Colin> >> >> > >> >> >> >> You might like to consider whether the controller (and maybe the view) >> >> would be simplified by combining the actions (and maybe views) and >> >> passing up and back a phase value to indicate which phase of the >> >> operation is current. >> >> To do this would require a hidden field as you have pointed out. >> >> Colin >> >> -- >> 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. >> > > > > -- > ------------------------------------------------------------- > visit my blog at http://jimlabs.heroku.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-/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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Pavling
2011-Feb-21 09:11 UTC
Re: Newb: Order page, multiple view single model question
On 21 February 2011 03:34, James allan To <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Question: Is there aright way of doing this (carry params values between > views) or should I just place the data from new in session as we move to > forward to the third page create a hash from session and save in model?My view would be that the order gets saved to the DB, and you use State Machine functionality to track which step a user is at. Validation *always* *only* goes in the model. Whether you have lots of ":if => Proc.new{|order| order.state :processing_attendees}" or have a separate OrderAttendeeRegister model which has_many attendees and all the associated validation. But if you store stuff in session, or hidden fields, you are blurring your separation (and it always ended in pain when I''ve seen it done those ways. HTH -- 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.
James allan To
2011-Feb-21 13:57 UTC
Re: Newb: Order page, multiple view single model question
Guys thank you so much and yes Jim that is what is happening i guess i''ll go for the hidden field. Thank you so much again. -- 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-/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.