I need to access params[:field_name] from within my Model. @params[:field_name] isn''t working?
Brendon Gleeson wrote:> I need to access params[:field_name] from within my Model. > @params[:field_name] isn''t working?Why would you need to access that?? There is probably a better way to do it Mikkel -- Posted via http://www.ruby-forum.com/.
Mikkel Bruun wrote: ...> Why would you need to access that?? > > There is probably a better way to do it... I got it : field_name <-- local var I have a complicated validate_on_create function i need it fot...
On 2.2.2006, at 12.54, Mikkel Bruun wrote:> Brendon Gleeson wrote: >> I need to access params[:field_name] from within my Model. >> @params[:field_name] isn''t working?It isn''t, and it shouldn''t.> > Why would you need to access that?? > > There is probably a better way to do itThat smells like very tight coupling between view and model. @params hash is something that belongs to the controller and individual http requests, not your model objects. Remember that AR is a totally distinct entity in Rails, and doesn''t know anything about what is happening on the controller/view side. If you got something you need to pass to the AR models, create a method where you can pass the value of the current params[:field_name]. //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2363 bytes Desc: not available Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060202/60a1cce6/smime.bin
Jarkko Laine wrote: ...> That smells like very tight coupling between view and model. @params > hash is something that belongs to the controller and individual http > requests, not your model objects. Remember that AR is a totally > distinct entity in Rails, and doesn''t know anything about what is > happening on the controller/view side. If you got something you need to > pass to the AR models, create a method where you can pass the value of > the current params[:field_name].... Sorry, I just needed to access the AR object, I thought i needed to use @params[] but I soon figured out what you mentioned above and was able to access ''field_name'' as a local var, This clarifies things quite alot. thx.
I forgot which one ... but one Login_system has Model constraints -- Rgds, --Siva Jagadeesan http://www.varcasa.com/ My First Rails Project. Education Through Collabration -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060202/fcf5a804/attachment.html