开发者

What is the proper way to access a join model's value?

I have users and projects and they are associated through a has_many :through model called ownerships. On the project show page, I would like to list the name of the project, the users associated with the project, and the type of association (called owner_type in开发者_StackOverflow社区 the ownership join model). I can't quite figure out how to do that though.

Also, if I have a project and the current_user, how do I figure out what the owner_type is for that user to that project?

Thanks!


I think it's safe to assume that in the project show, @project is defined. Correct? So, a possible view could look something like...

app/views/projects/show.html.erb

<h1><%= @project.name %></h1>
<ul>
    <%= render :partial => 'ownership', :collection => @project.ownerships %>
</ul>

app/views/projects/_ownership.html.erb

<li><strong><%= ownership.user.name %></strong> (<%= ownership.ownership_type %>)</li>

I don't understand your second question though. I suggest posting that as an entirely separate question, maybe with some more clarification.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜