【发布时间】:2023-03-20 12:24:02
【问题描述】:
我正在尝试使用“mongoid-tags-arent-hard”Gem 使用 rails 4.2 和 mongoid 4 向我的发布/评论应用程序添加标签功能。
Gem 是根据文档设置的,但是 Post 正在保存而没有标签。在 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
后控制器的一部分:
def create
@post = Post.new(post_params)
@post.user = current_user
def post_params
params.require(:post).permit(:title, :description, :tags)
end
【问题讨论】:
标签: ruby-on-rails ruby mongoid