7li*_*rts 3 ruby ruby-on-rails acts-as-taggable-on strong-parameters
如何在rails 4中使用具有强参数的acts_as_taggable_on gem?
有:
class User < ActiveRecord::Base
acts_as_tagger
end
class Post < ActiveRecord::Base
acts_as_taggable
end
@post = current_user.tag(@post, :with => :tag_list)
def post_params
params.require(:post).permit(:text, :user_id, :tag_list)
end
Run Code Online (Sandbox Code Playgroud)
如何将(post_params)添加到@post?
Hol*_*off 10
你应该像这样指定你允许的参数:
def post_params
params.require(:post).permit(:text, :user_id, { tag_list: [] })
end
Run Code Online (Sandbox Code Playgroud)
这应该使他们在控制器操作中保存tag_list.