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.
D5e95369c4366d0ccd6a21828ca11c79?d=identicon&s=25 Brendon Gleeson (Guest)
on 2006-02-02 11:49
(Received via mailing list)
I need to access params[:field_name] from within my Model.
@params[:field_name] isn't working?
C7669e8b5676f61fdf202230cbcf72d8?d=identicon&s=25 Mikkel Bruun (mikkel)
on 2006-02-02 11:54
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
D5e95369c4366d0ccd6a21828ca11c79?d=identicon&s=25 Brendon Gleeson (Guest)
on 2006-02-02 12:01
(Received via mailing list)
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...
82476266af9d460415d8f1fc16bb54ed?d=identicon&s=25 Jarkko Laine (jarkko)
on 2006-02-02 12:07
(Received via mailing list)
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 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
D5e95369c4366d0ccd6a21828ca11c79?d=identicon&s=25 Brendon Gleeson (Guest)
on 2006-02-02 13:26
(Received via mailing list)
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.
33bb150cf13d87bce4e80569ca317647?d=identicon&s=25 Siva Jagadeesan (Guest)
on 2006-02-02 18:34
(Received via mailing list)
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
This topic is locked and can not be replied to.