我使用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 %>
,它也不工作
谢谢
尝试将其添加到您的项目模型(在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]
怎么样:
row :tags do
resource.tag_list.join(", ")
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 %>