[英]Rails: Why does view page show the ActiveRecord Hashes?
I have two models CategoryFolder and Categories. 我有两个型号CategoryFolder和Categories。 CategoryFolder has many Categories, and Category belongs to CategoryFolder with foreign_id "parent_id"
CategoryFolder有很多类别,Category属于CategoryFolder,其中foreign_id为“parent_id”
For some reason, when I try to loop through the folders and list the categories within them, the view page displays the record hashes, and I don't know how to get rid of it: 出于某种原因, 当我尝试遍历文件夹并列出其中的类别时,视图页面显示记录哈希,我不知道如何摆脱它:
Categories Controller 分类控制器
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
Categories View#index 分类查看#index
<% @folders.each do |folder| %>
<%= folder.categories.order("title ASC").each do |category| %>
<%= render partial: 'table_list', locals: { category: category } %>
<% end %>
<% end %>
The Folders-Categories relationship has been causing a few errors lately, and I'm not sure whether the relations are set up weirdly. Folders-Categories关系最近引起了一些错误,我不确定关系是否设置得很奇怪。 For example, even when I delete a category, the category title will still show under something like "@folder.categories.each ~ link_to title" and when I click the title it gives me an error page.
例如, 即使我删除一个类别,类别标题仍将显示在“@ folder.categories.each~link_to title”之类的内容中 ,当我点击标题时,它会给我一个错误页面。
Category.rb Category.rb
belongs_to :folder, class_name: "CategoryFolder", :foreign_key => "parent_id"
CategoryFolder.rb 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 %>
Your loop should not have an equal sign, that equal prints out the loop results. 你的循环不应该有一个等号,等于打印出循环结果。
<% @folders.each do |folder| %>
<% folder.categories.order("title ASC").each do |category| %>
<%= render partial: 'table_list', locals: { category: category } %>
<% end %>
<% end %>
The second line should have no sign 第二行应该没有任何迹象
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.