2017-08-25 133 views
0

Acts-as-Taggable-on無法正確輸出名稱列,也不能正確顯示對象本身的信息的整個散列。如何設置顯示頁面以分別爲模型打印每個標籤?我到目前爲止的代碼如下。Acts-as-Taggable-顯示散列對象而不是標籤名稱

show.html.erb

<%= @user.user_profile.tags.each do |tag| %> 
<%= tag.name %> 
<% end %> 

結果顯示頁

#<ActsAsTaggableOn::Tag::ActiveRecord_Associations_CollectionProxy:0x2b7534d0> games [#<ActsAsTaggableOn::Tag id: 1, name: "games", created_at: "2017-08-25 15:54:30", updated_at: "2017-08-25 15:54:30", taggings_count: 1>] 1 

控制檯輸出

Rendering users/show.html.erb within layouts/application 
    UserProfile Load (8.0ms) SELECT "user_profiles".* FROM "user_profiles" WHERE "user_profiles"."user_id" = $1 LIMIT $2 [["user_id", 5], ["LIMIT", 1]] 
    ActsAsTaggableOn::Tag Load (15.0ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2 AND "taggings"."context" = $3 [["taggable_id", 2], ["taggable_type", "UserProfile"], ["context", "tags"]] 
    ActsAsTaggableOn::Tagging Load (2.0ms) SELECT "taggings".* FROM "taggings" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2 [["taggable_id", 2], ["taggable_type", "UserProfile"]] 
    ActsAsTaggableOn::Tag Load (25.0ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2 AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL) [["taggable_id", 2], ["taggable_type", "UserProfile"]] 

user_profile.rb

class UserProfile < ApplicationRecord 
    acts_as_taggable 
    acts_as_taggable_on :abilities 
end 
上示出3210

回答

1

+0

我一定累洛爾(在第一行中的 '<%' 之後沒有 '=')嘗試

<% @user.user_profile.tags.each do |tag| %> <%= tag.name %> <% end %> 

。謝謝,這正是我需要做的。 –

相關問題