Hello ~ Is there a way to determine within a model which controller/action instantiated the model? Thx, -- Ben Reubenstein http://www.benr75.com
On 4/28/06, Ben Reubenstein <benr@x-cr.com> wrote:> > Hello ~ > > Is there a way to determine within a model which controller/action > instantiated the model?Your models should not be concerend with things like controllers, views, etc. They should operate independently not even concerned that they are in a web-framework (many people use ActiveRecord for CLI apps). What is it that you are trying to do? Josh -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060428/d60bff8d/attachment.html
On Apr 28, 2006, at 04:54 PM, Ben Reubenstein wrote:> Is there a way to determine within a model which controller/action > instantiated the model?This might sound like a stupid question, but why should your model care? Something asked for a new instance, so that''s what it gives it. The "outside world" is very frightening to your model, so you shouldn''t try to teach it about things beyond what it normally contains. :) -Brian
>Your models should not be concerend with things like controllers,views, etc. They >should operate independently not even concerned that they are in a web-framework (many >people use ActiveRecord for CLI apps). I agree... However I have run into an instance in a wizard-type flow where conditional validation would make my controller dryer. I was considering using acts_as_state for creating different validations as I change the state of the object, but I do not want to turn my Models into modules. Basically, I load up an object and as the wizard progresses more of the data is added to the object. I considered passing params between steps, but if a user only goes part of the way through, it would be nice to have their progress saved when they return. Maybe I am just not seeing the easy solution on this one... Thx for everyone''s help, Ben On 4/28/06, Brian Hughes <brianvh@alum.dartmouth.org> wrote:> On Apr 28, 2006, at 04:54 PM, Ben Reubenstein wrote: > > Is there a way to determine within a model which controller/action > > instantiated the model? > > This might sound like a stupid question, but why should your model > care? Something asked for a new instance, so that''s what it gives it. > > The "outside world" is very frightening to your model, so you > shouldn''t try to teach it about things beyond what it normally > contains. :) > > -Brian > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Ben Reubenstein benr@x-cr.com http://www.benr75.com
Ben, Have you considered saving the model for every stage of the wizard? Then validate for each post, conditional upon the stage of the wizard you''re on? You could even capture the last stage the user was at, and restore them to this page when they return. I use this technique, and it works very well. I''ve implemented it with a (currently) 21 page wizard, and this pattern model works very well. cheers, Jodi On 28-Apr-06, at 5:19 PM, Ben Reubenstein wrote:>> Your models should not be concerend with things like controllers, > views, etc. They >should operate independently not even concerned > that they are in a web-framework (many >people use ActiveRecord for > CLI apps). > > I agree... However I have run into an instance in a wizard-type flow > where conditional validation would make my controller dryer. I was > considering using acts_as_state for creating different validations as > I change the state of the object, but I do not want to turn my Models > into modules. > > Basically, I load up an object and as the wizard progresses more of > the data is added to the object. I considered passing params between > steps, but if a user only goes part of the way through, it would be > nice to have their progress saved when they return. > > Maybe I am just not seeing the easy solution on this one... > > Thx for everyone''s help, > > Ben > > > On 4/28/06, Brian Hughes <brianvh@alum.dartmouth.org> wrote: >> On Apr 28, 2006, at 04:54 PM, Ben Reubenstein wrote: >> > Is there a way to determine within a model which controller/action >> > instantiated the model? >> >> This might sound like a stupid question, but why should your model >> care? Something asked for a new instance, so that''s what it gives it. >> >> The "outside world" is very frightening to your model, so you >> shouldn''t try to teach it about things beyond what it normally >> contains. :) >> >> -Brian >> >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > -- > Ben Reubenstein > benr@x-cr.com > http://www.benr75.com > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails