[英]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.