I am trying to write a simple application and I am stumped!
我想写一个简单的应用程序,我很难过!
Here is what I have as a view for users/show/1:
以下是我对用户/ show / 1的看法:
<p>
<b>User:</b>
<%=h @user.login %>
</p>
<% if @user.reviews.empty? %>
No Analyst Reports yet
<% else %>
<% for review in @user.reviews %>
<%= review.vendor_id %><%= review.summary %><br />
<hr class="span-5" />
<% end %>
<% end %>
I created a relationship where user :has_many reviews and vendor :has_many reviews
我创建了一个用户:has_many评论和供应商:has_many评论的关系
So I assume that there should be a value for review.vendor_id, where vendor_id is just automatically created and can be displayed.
所以我假设review.vendor_id应该有一个值,其中vendor_id只是自动创建并可以显示。
Thank you :)
谢谢 :)
Here is my Reviews model:
这是我的评论模型:
class Review < ActiveRecord::Base
belongs_to :vendor
belongs_to :user
end
Actually this has been solved, I now need to go through the for-loop and display attributes of vendor....see my other question please! Thanks!
实际上这已经解决了,我现在需要通过供应商的for-loop和显示属性....请看我的其他问题!谢谢!
1 个解决方案
#1
Does your review model have the corresponding belongs_to :user belongs_to :vendor - ?
您的评论模型是否具有相应的belongs_to:user belongs_to:vendor - ?
Also, when a review is created, have you checked that the vendor_id is filled? check this question: How do you set an attribute when creating an ActiveRecord object?
此外,创建评论时,您是否检查过vendor_id是否已填写?检查这个问题:创建ActiveRecord对象时如何设置属性?
#1
Does your review model have the corresponding belongs_to :user belongs_to :vendor - ?
您的评论模型是否具有相应的belongs_to:user belongs_to:vendor - ?
Also, when a review is created, have you checked that the vendor_id is filled? check this question: How do you set an attribute when creating an ActiveRecord object?
此外,创建评论时,您是否检查过vendor_id是否已填写?检查这个问题:创建ActiveRecord对象时如何设置属性?