On 13 October 2010 21:05, Leonel *.* <[email protected]> wrote: > I have an accounts table > ACCOUNTS > id > company_name > > and a users table > USERS > id > username > password > account_id > > I want a page where I display the company_name for the user. So far, I > managed to get the user_id from the session... > <%= session[:user_id] %> > > Now, I guess I can use the user_id, to find it's account_id, and then > match the account_id and get the company_name.
If you have a user in current_user for example then the company is current_user.company, so the name is current_user.company.name. Such is the magic of Rails. Watch out for the cas when the user does not have a company, in which current_user.company will be nil. Check out the rails guide on ActiveRecord relationships to see how this all works. Colin > > I don't know, maybe I'm overcomplicating things. I just managed to get > the user_id and I'm now stuck. > > -- > 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 [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. > > -- 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.

