I have a rather complex object with a number of attributes. For a variety of reasons, I would like one view to create the object with only a couple of fields completed, then a second and third view to finish all the fields. I would like the model to validate_presence_of all these fields, since eventually I need them all there, and I would like each page to validate its portion of the fields that that view presents. How do I best do that? The only thing I can think of is some kind of use of single table inheritance, with each child object filling in a portion of the fields of the total. But that seems weird. Does anyone have a better idea? Thanks for any advice, Shelby -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060613/7d42a8b9/attachment.html
Shelby Westman <shelby.westman@gmail.com> wrote: I have a rather complex object with a number of attributes. For a variety of reasons, I would like one view to create the object with only a couple of fields completed, then a second and third view to finish all the fields. I would like the model to validate_presence_of all these fields, since eventually I need them all there, and I would like each page to validate its portion of the fields that that view presents. How do I best do that? The only thing I can think of is some kind of use of single table inheritance, with each child object filling in a portion of the fields of the total. But that seems weird. Does anyone have a better idea? Thanks for any advice, Shelby As long as your object is serializable (it probably is), you can just instantiate your model, fill in whatever you''ve got so far, slap that sucker in the session and pull it back out in the next step. hth, phil -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060613/3a3baa16/attachment.html
Hi Shelby, Object.save_with_validation(false) might give you the flexibility you''re looking for. hth, Bill -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060613/37a76da5/attachment-0001.html
Both: Object.save_with_validation(false) might give you the flexibility you''re> looking for. >and putting the object it in the session would work. But neither would allow me to validate only the portion of the object that I fill in with each of the views that I use to gradually complete filling in all the fields of the object. Shelby -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060613/9970c208/attachment.html
Bill Walton <bill.walton@charter.net> wrote: Object.save_with_validation(false) might give you the flexibility you''re looking for. The trouble in this case is you save a lot of invalid rows into your database -- what if somebody bounces before completing the process? So you then need some way of dealing with the invalid rows and deciding whether they should get deleted yet, or if they are still in process. cheers, phil -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060613/60c0c07b/attachment.html
Shelby Westman <shelby.westman@gmail.com> wrote: Both: Object.save_with_validation (false) might give you the flexibility you''re looking for. and putting the object it in the session would work. But neither would allow me to validate only the portion of the object that I fill in with each of the views that I use to gradually complete filling in all the fields of the object. Shelby _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails Ahhh... good point. You can check if individual fields have errors like so: @foo = Foo.new(params[:foo]) @foo.valid? #No, cause we haven''t finished completing it yet! @foo.errors.invalid? :phone # => true if phone is invalid There might be an even cleaner way, but I haven''t found it yet if there is. -phil -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060613/465f53d0/attachment.html
Absolutely right. As is Phillip. Server-side validation has it''s limitations. You might want to consider JS validation on the client-side. hth, Bill ----- Original Message ----- From: Shelby Westman To: rails@lists.rubyonrails.org Sent: Monday, June 12, 2006 9:09 PM Subject: Re: [Rails] model validation across multiple views Both: Object.save_with_validation (false) might give you the flexibility you''re looking for. and putting the object it in the session would work. But neither would allow me to validate only the portion of the object that I fill in with each of the views that I use to gradually complete filling in all the fields of the object. Shelby ------------------------------------------------------------------------------ _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060613/08fcdf73/attachment.html
search the mailing list for Wizards(damn gmane is down again, otherwise I''d send you a reference) general idea is to use a stage (input type hidden) and then validate particular attributes based it, ala, #stage 1 entry validation validates_presence_of :patient_id, :if => :after_stage_one, :message => " must be selected" #stage 2 entry validation validates_presence_of :age, :if => :at_stage_two, :message => " must be entered" validates_numericality_of :age, :if => :at_stage_two, :only_integer => true, :message => " must be numeric" def at_stage_one stage == 1 end I use this method for a 20+ entry screen. Works great. In your controller then, if model.valid? model.save else render :partial => errors end let me know if I can be more verbose. Cheers, Jodi On 12-Jun-06, at 10:09 PM, Shelby Westman wrote:> Both: > > Object.save_with_validation (false) might give you the flexibility > you''re looking for. > > and putting the object it in the session would work. But neither > would allow me to validate only the portion of the object that I > fill in with each of the views that I use to gradually complete > filling in all the fields of the object. > > Shelby > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060613/d0c72b13/attachment.html