[Rails] Re: RES: Newb question- method not working

Rath --- rathjunk at gmail.com
Wed Aug 9 07:59:58 GMT 2006


<%= @uname = User.find_by_id(session[:user]) %>
or
<%= @uname = User.find_by_id(session[:user].id) %>

This will be cleaner... remember that find_by_XX is the same as 
find(:first, :conditions => ["XX = ?", XX]) or find_all_by_XX returns 
:all

You can check the section "Dynamic attribute-based finders" in
http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000858


Romeu Henrique Capparelli Fonseca wrote:
> Maybe this:
>  <% a = session[:user] %>
>  <% uname = User.find(:first, :conditions => "id = '#{a}'") %>
>  <%= @uname %>

-- 
Posted via http://www.ruby-forum.com/.


More information about the Rails mailing list