Forum: Ruby on Rails access controller var within model

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Brendon G. (Guest)
on 2006-02-02 12:49
(Received via mailing list)
I need to access params[:field_name] from within my Model.
@params[:field_name] isn't working?
Mikkel B. (Guest)
on 2006-02-02 12:54
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
Brendon G. (Guest)
on 2006-02-02 13:01
(Received via mailing list)
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. (Guest)
on 2006-02-02 13:07
(Received via mailing list)
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
Brendon G. (Guest)
on 2006-02-02 14:26
(Received via mailing list)
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.
Siva J. (Guest)
on 2006-02-02 19:34
(Received via mailing list)
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
This topic is locked and can not be replied to.