访问连接模型值的正确方法是什么?
我有用户和项目,它们通过称为所有权的 has_many :through 模型关联。在项目显示页面上,我想列出项目的名称、与项目关联的用户以及关联类型(在所有权加入模型中称为owner_type)。但我不太清楚该怎么做。
另外,如果我有一个项目和 current_user,我如何确定该项目的该用户的owner_type 是什么?
谢谢!
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 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为可以安全地假设在项目显示中定义了@project。正确的?因此,可能的视图可能类似于...
app/views/projects/show.html.erb
app/views/projects/_ownership.html.erb
但我不明白你的第二个问题。我建议将其作为一个完全独立的问题发布,也许需要更多说明。
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
app/views/projects/_ownership.html.erb
I don't understand your second question though. I suggest posting that as an entirely separate question, maybe with some more clarification.