Definately @user = User.find(session[:id]) would go in the controller. You can also make a helper called something like current_user so you can access the user in the view without having it to set in the controller action every time. This makes it possible to write something like:
<%= current_user.name %> in the view. Google stuff on Rails helpers but I normally try to not get them bloated. Its the old saying: Fat model, skinny controller. As Fred pointed out its frowned upon to have logic in the view. Regards Stefano On Jul 13, 9:41 am, Frederick Cheung <[email protected]> wrote: > On 12 Jul 2011, at 22:02, ses <[email protected]> wrote: > > > Firstly I'm coming from a Java EE background and building up my Rails > > knowledge slowly in my (relatively limited!) free time, so apologies > > if this is rudimentary stuff. > > > The common pattern for user sessions seems to be something like > > 'session[:id] = user.id' in the controller and > > 'User.find(session[:id])' in the view. > > > However its also possible to just set an instance variable once a user > > has logged in, e.g. '@id = user.id'. Due to some rails magic the > > instance variable of the controller gets passed to the view, thus > > facilitating a kind of session persistence. I'd hazard a guess at > > saying this is probably bad form but due to not fully understanding > > how the instance variable is available I'm not sure. > > The passing of instance variables from controller to view is fairly central > to rails. If anything, it is doing too much in the view that is frowned upon. > Personally I would do something like > > @user = User.find session[:id] in the controller > > And then use @user in the view > > Fred > > > > > > > > > What's the general consensus on this? > > > -- > > You received this message because you are subscribed to the Google Groups > > "Ruby on Rails: Talk" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group > > athttp://groups.google.com/group/rubyonrails-talk?hl=en. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

