[Rails] Re: A Good Tutorial on Params and Variables

Carl-Johan Kihlbom
2006-04-29T22:13:38Z

Session variables are available in all Controllers. Models don''t have
access to session variables though. That would tightly couple your
models to your controllers, and that violates some of the ideas of
seperation behind MVC. If a method in a model needs a session
variable, the controller should pass along that variable when calling
the method.

Session variables are set and read through the session method in the
controller. For example:

session[:user_id] = @user.id

Parameters are very straightforward. Just pass them along in you
redirect_to och link_to (etc.) calls and the receiving controller will
get them:

redirect_to :action => ''some_action'', :parameter1 =>
''a value'',
:parameter2 => ''another value''

You get parameters from the params method in the controller:

params[:parameter1]

Hope that makes it a bit clearer. Also, check out
http://weblog.rubyonrails.org/articles/2006/04/25/use-params-not-params

/ CJ

On 4/29/06, Marston A. <marston@marstononline.com>
wrote:
> I second that.
>
> Ted Battreall wrote:
> > I have found various posts about instance variables, session variables
> > and parameters (each of which seems to use differnet syntax and have
> > different view on the "best practice") I would like to find
a single,
> > reliable source that provides a good overview on all of it.
> >
> > Specifically, I would like to learn how to pass parameters between
> > controllers and how to set session variables so they can be seen from
> > any Controller/Model.
> >
> > Thanks
>
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>