# Problem displaying author's name on the post assigned

**URL:** <https://www.ruby-forum.com/t/problem-displaying-authors-name-on-the-post-assigned/128269>\
**Category:** Rails\
**Created:** [February 6, 2008, 10:11am UTC](https://www.ruby-forum.com/t/problem-displaying-authors-name-on-the-post-assigned/128269 "2008-02-06T10:11:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![flychunjae](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/3ab097/32.png) [@flychunjae](https://www.ruby-forum.com/u/flychunjae)\
**Post date:** [February 6, 2008, 10:11am UTC](https://www.ruby-forum.com/t/problem-displaying-authors-name-on-the-post-assigned/128269/1 "2008-02-06T10:11:07Z")

</div>

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:  
  
Posted by : \<%= link\_to @post.user\_id -%\>  
\<%= distance\_of\_time\_in\_words\_to\_now(@post.created\_at) %\> ago

\<%= @post.location %\>

thank you alll

---

<div class="post-metadata">

**Author:** ![flychunjae](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/3ab097/32.png) [@flychunjae](https://www.ruby-forum.com/u/flychunjae)\
**Post date:** [February 6, 2008, 4:17pm UTC](https://www.ruby-forum.com/t/problem-displaying-authors-name-on-the-post-assigned/128269/2 "2008-02-06T16:17:21Z")

</div>

Richard Y. 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:  
>   
> Posted by : \<%= link\_to @post.user\_id -%\>  
> \<%= distance\_of\_time\_in\_words\_to\_now(@post.created\_at) %\> ago
> 
> \<%= @post.location %\>
> 
> thank you alll

Try 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.
