我使用activeadmin并充当可标记的gem。当我在activeadmin上插入标签时,它会保存标签,但不会在视图中显示标签
activeadmin模型:
ActiveAdmin.register Project do
index do
column :id
column :name
column :created_at
column :tag_list
default_actions
end
form(:html => { :multipart => true }) do |f|
f.inputs do
f.input :name
f.input :tag_list, :label => "Tags", :hint => 'Comma separated'
f.input :content, :input_html => {:class => "ckeditor"}
f.input :image, :as => :file
end
f.buttons
end
end
模型:
class Project < ActiveRecord::Base
attr_accessible :content, :name, :image, :tag_list
mount_uploader :image, ImageUploader
acts_as_taggable
def previous_project
self.class.first(:conditions => ["name < ?", name], :order => "name desc")
end
def next_project
self.class.first(:conditions => ["name > ?", name], :order => "name asc")
end
end
查看:
<% @projects.each do |project| %>
<figure class="d1-d3">
<%= image_tag project.image_url(:thumb) if project.image? %>
<figcaption>
<h4><%= link_to project.name, project %></h4>
<% project.tag_list %>
</figcaption>
</figure>
<% end %>
我尝试使用<%= project.tags %>
并且它无法正常工作
由于
答案 0 :(得分:0)
尝试将其添加到您的项目模型中(在acts_as_taggable下面)
acts_as_taggable_on :tags
请记住运行迁移,例如:
create_table :tags do |t|
t.string :name
end
create_table :taggings do |t|
t.references :tag
# You should make sure that the column created is
# long enough to store the required class names.
t.references :taggable, :polymorphic => true
t.references :tagger, :polymorphic => true
# limit is created to prevent mysql error o index lenght for myisam table type.
# http://bit.ly/vgW2Ql
t.string :context, :limit => 128
t.datetime :created_at
end
add_index :taggings, :tag_id
add_index :taggings, [:taggable_id, :taggable_type, :context]
答案 1 :(得分:0)
怎么样:
row :tags do
resource.tag_list.join(", ")
end
答案 2 :(得分:0)
在视图中错过了等号
查看:
<% @projects.each do |project| %>
<figure class="d1-d3">
<%= image_tag project.image_url(:thumb) if project.image? %>
<figcaption>
<h4><%= link_to project.name, project %></h4>
<%= project.tag_list %>
</figcaption>
</figure>
<% end %>