Access controller var within model

I need to access params[:field_name] from within my Model.
@params[:field_name] isn’t working?

Brendon G. 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

Mikkel B. 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…

Jarkko L. 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.

On 2.2.2006, at 12.54, Mikkel B. wrote:

Brendon G. 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 it

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].

//jarkko

I forgot which one … but one Login_system has Model constraints


Rgds,
–Siva J.
http://www.varcasa.com/
My First Rails Project.
Education Through Collabration