Ruby on rails 在显示哈希对象而不是标记名时充当标记
Acts as Taggable on无法正确打印出仅名称列,而不是对象本身的整个信息散列。如何设置显示页面以分别打印模型的每个标记?到目前为止,我掌握的代码如下 show.html.erbRuby on rails 在显示哈希对象而不是标记名时充当标记,ruby-on-rails,ruby,acts-as-taggable-on,Ruby On Rails,Ruby,Acts As Taggable On,Acts as Taggable on无法正确打印出仅名称列,而不是对象本身的整个信息散列。如何设置显示页面以分别打印模型的每个标记?到目前为止,我掌握的代码如下 show.html.erb <%= @user.user_profile.tags.each do |tag| %> <%= tag.name %> <% end %> 用户_profile.rb class UserProfile < ApplicationRecord acts_as
<%= @user.user_profile.tags.each do |tag| %>
<%= tag.name %>
<% end %>
用户_profile.rb
class UserProfile < ApplicationRecord
acts_as_taggable
acts_as_taggable_on :abilities
end
试一试
没有“=”之后的“我一定很累了,哈哈。谢谢,这正是我需要做的。
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"]]
class UserProfile < ApplicationRecord
acts_as_taggable
acts_as_taggable_on :abilities
end
<% @user.user_profile.tags.each do |tag| %>
<%= tag.name %>
<% end %>