hi all,
newb still learning here, i''m having problems displaying the
author''s
login name and instead it''s displaying the author''s id# in
mysql. i''m
currently using the acts_as_authenticated plug in which seems to be
working fine and i''ve assigned the posts to the authors by: @post.user
current_user
the user login is stored as login but i have no idea how to call the
user''s login field in the controller i was thinking using something
like
@user = @user.login but it didn''t work so i gues i''m doing
something
wrong.
here is the code:
in the controller:
def show
    store_location
    @post = Post.find(params[:id])
  end
in the view:
<span>
Posted by : <%= link_to @post.user_id -%>
<%= distance_of_time_in_words_to_now(@post.created_at) %> ago
</span>
<span>
<%= @post.location %></span>
thank you alll
-- 
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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Jeremy Weiskotten
2008-Feb-06  15:17 UTC
Re: Problem displaying author''s name on the post assigned
Richard Yoo wrote:> hi all, > > newb still learning here, i''m having problems displaying the author''s > login name and instead it''s displaying the author''s id# in mysql. i''m > currently using the acts_as_authenticated plug in which seems to be > working fine and i''ve assigned the posts to the authors by: @post.user > current_user > > the user login is stored as login but i have no idea how to call the > user''s login field in the controller i was thinking using something like > @user = @user.login but it didn''t work so i gues i''m doing something > wrong. > > here is the code: > > in the controller: > def show > store_location > @post = Post.find(params[:id]) > > end > > in the view: > <span> > Posted by : <%= link_to @post.user_id -%> > <%= distance_of_time_in_words_to_now(@post.created_at) %> ago > </span> > > <span> > <%= @post.location %></span> > > > thank you alllTry this: Posted by: <%= link_to @post.user.login, :controller => ''users'', :action => ''show'', :id => @post.user %> Assuming you have a UsersController with a show action, this should work. You could clean it up a bit with name routes. -- 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---