[英]Rails: Why does view page show the ActiveRecord Hashes?
我有两个型号CategoryFolder和Categories。 CategoryFolder有很多类别,Category属于CategoryFolder,其中foreign_id为“parent_id”
出于某种原因, 当我尝试遍历文件夹并列出其中的类别时,视图页面显示记录哈希,我不知道如何摆脱它:
分类控制器
def index
@folders = current_account.category_folders.order("created_at ASC")
@categories = current_account.categories.where(parent_id: nil).order("created_at ASC")
# authorize! :read, Category
render :layout => "admin"
end
分类查看#index
<% @folders.each do |folder| %>
<%= folder.categories.order("title ASC").each do |category| %>
<%= render partial: 'table_list', locals: { category: category } %>
<% end %>
<% end %>
Folders-Categories关系最近引起了一些错误,我不确定关系是否设置得很奇怪。 例如, 即使我删除一个类别,类别标题仍将显示在“@ folder.categories.each~link_to title”之类的内容中 ,当我点击标题时,它会给我一个错误页面。
Category.rb
belongs_to :folder, class_name: "CategoryFolder", :foreign_key => "parent_id"
CategoryFolder.rb
has_many :categories, class_name: "Category", foreign_key: "parent_id"
<% @folders.each do |folder| %>
<%= folder.categories.order("title ASC").each do |category| %>
<%= render partial: 'table_list', locals: { category: category } %>
<% end %>
<% end %>
你的循环不应该有一个等号,等于打印出循环结果。
<% @folders.each do |folder| %>
<% folder.categories.order("title ASC").each do |category| %>
<%= render partial: 'table_list', locals: { category: category } %>
<% end %>
<% end %>
第二行应该没有任何迹象
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.