Rails 4: text_field for acts_as_taggable_on not separating tags with a comma

▼魔方 西西 提交于 2019-11-30 19:38:39

Apparently this is a new security feature.

I solved the comma separation issue by doing:

<% @article.tag_types.each do |tag| %>
<div class="form-group">
  <strong><%= f.label tag.to_s.titleize %></strong><br />
  <% tag_sym = "#{tag.to_s.singularize}_list".to_sym %>
  <% tag_list = "#{tag.to_s.singularize}_list" %>
  <%= f.text_field tag_sym, value: @article.send(tag_list).to_s, :placeholder => "Comma-separated list of #{tag.to_s}", class: 'form-control' %>
</div>
<% end %>

Thanks! Since I am using ActiveAdmin with Formtastic I made a custom input.

So I created a new class: app/inputs/tag_list_input.rb with:

class TagListInput < Formtastic::Inputs::StringInput
  def input_html_options
    super.merge(:value => "#{@object.send(method).to_s.html_safe}")
  end
end

and using this like:

f.input :some_tag_list, :as => :tag_list, :label => "SomeTags"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!