mongoid-tags-arent-hard 不工作

mongoid-tags-arent-hard not working

我正在尝试使用 "mongoid-tags-arent-hard" Gem 将标记功能添加到我的 Post/comment 应用程序,使用 rails 4.2 和 mongoid 4。

Gem 是根据文档设置的,但是 Post 是在没有标签的情况下保存的。 post 文档标签字段为空。

以下是view/model/controller:

如果我有任何错误,请告诉我。

View
    _form.html.erb
        <p>
          <%= f.label :tags %><br />
          <%= text_field_tag 'post[tags]' %>
        </p>

class Post

  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::TagsArentHard

  taggable_with :tags

  field :title, type: String
  slug :title

  field :description, type: String
  field :starred, type: Boolean

  validates :title, :presence => true, :length => { :minimum => 20, :allow_blank => false }

  embeds_many :comments
  embeds_many :answers

  belongs_to :user

End

部分 Post 控制器:

def create
    @post = Post.new(post_params)
    @post.user = current_user

def post_params
      params.require(:post).permit(:title, :description, :tags)
    end

更正了视图,如下所示。现在一切正常。

<div class="field">
  <%= f.label :tags %><br>
  <%= f.text_field :tags %>
</div>