Colin Law wrote in post #950219: > On 14 October 2010 17:27, Leonel *.* <li...@ruby-forum.com> wrote: >> >> protect_from_forgery >> >> @user_id = User.find_by_id(session[:user_id]) >> @account_id = @user_id.account.id > > Doing it like that means that it will get executed when the controller > loads, which in production will be only once. You need to put it in a > method of application_controller then call it from your code when you > want to know the result. > > Are you using authlogic? If so I am sure the examples of how to use > it include how to do a current_user method.
So you mean doing something like this in the application controller? def current_user User.find_by_id(session[:user_id]) end I use the user id, the account id, the account name and the account id in several parts of the application. Everytime I need to access the data I have to add something like this on each controller method... class AccountsController < ApplicationController # GET /accounts # GET /accounts.xml def index @accounts = Account.all @company_id = User.find(session[:user_id]).account.id @company_name = User.find(session[:user_id]).account.name @company_address_one = User.find(session[:user_id]).account.address_one @company_address_two = User.find(session[:user_id]).account.address_two @company_city = User.find(session[:user_id]).account.city @company_state = User.find(session[:user_id]).account.state @company_zip = User.find(session[:user_id]).account.zip @company_web_address = User.find(session[:user_id]).account.web_address @company_phone_number_office = User.find(session[:user_id]).account.phone_number_office @company_phone_number_fax = User.find(session[:user_id]).account.phone_number_fax How can I make the company name available to all views with something like this... @company_name -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.