我正在尝试使用“mongoid-tags-arent-hard”Gem来使用rails 4.2和mongoid 4为我的Post / comment应用程序添加标记功能。
Gem是根据文档设置的,但是Post没有标签就保存了。在帖子文档标记字段为空。
以下是视图/模型/控制器:
如果我犯了任何错误,请告诉我。
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
答案 0 :(得分:0)
更正了如下所示的视图。现在一切都很好。
<div class="field">
<%= f.label :tags %><br>
<%= f.text_field :tags %>
</div>