Display USERNAME next to post

Hello,

Iā€™m sure all of you have done this before,

basically users can post new posts, but i want their names next to the
post.

I have a current_user helper method, but i dont know how to display a
static one next to that one post.

Anyhelp would be appreciated :slight_smile: thanks

Hi,
As you want to display owner of post next to the post. Use
post.user.name to display owner of the post. I think there is one to
many relation exist between user & post model.

user has_many Post .
post has_one user .

On Mon, Apr 12, 2010 at 11:18 AM, Priyanka P.
[email protected]wrote:

To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected][email protected]
.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.

ā€“
Thanks:
Rajeev sharma

yes as per first reply you should have has_many and belongs_to
relationship
between user and post.

user has_many posts
post belongs_to user

so that you can get post.user.name etc.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs