用这个把头撞在墙上。我已经实现了acts_as_taggable_on,但即使我已将参数列入白名单(如文档中所示),我也会收到一个未经许可的参数错误。
无法弄清楚原因。
所有帮助表示赞赏。
在course.rb
class Course < ActiveRecord::Base
acts_as_taggable
acts_as_taggable_on :skills
[...]
end
在courses_controller.rb
中 [...]
def update
@course.skill_list = params[:skill_list]
respond_to do |format|
if @course.update(course_params)
format.html { redirect_to @course, notice: 'Course was successfully updated.' }
format.json { render :show, status: :ok, location: @course }
else
format.html { render :edit }
format.json { render json: @course.errors, status: :unprocessable_entity }
end
end
end
def course_params
params.require(:course).permit(:name, :headline, :user_provider_name, :provider_id, :cost, :location, :duration, :skill_level, :no_provider, :format, :website, :contact, :description, review: [:headline, :body, :course_id, :user_id, :score], :skills => [], :skill_list => [])
end
如果:技能不是数组,它也会引发错误。
在_form.html.erb
中<div class="field">
<%= f.label :skills %><br>
<%= f.text_field :skill_list %>
来自日志:
Started PATCH "/courses/15" for 127.0.0.1 at 2015-03-24 23:10:40 +0000
Processing by CoursesController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"A/4NFlFKwOU/tPQxfbMfh8vsu1dD4lGplqIbna1kooU=", "course"=>{"name"=>"Test course", "skill_list"=>"coding, html, debugging", "cost"=>"", "location"=>"", "duration"=>"", "skill_level"=>"", "format"=>"", "website"=>"", "contact"=>"", "headline"=>"", "description"=>""}, "commit"=>"Update Course", "id"=>"15"}
[1m[35mCourse Load (0.0ms)[0m SELECT "courses".* FROM "courses" WHERE "courses"."id" = ? LIMIT 1 [["id", 15]]
[1m[36mActsAsTaggableOn::Tag Load (1.0ms)[0m [1mSELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = ? AND "taggings"."taggable_type" = ? AND (taggings.context = 'skills' AND taggings.tagger_id IS NULL)[0m [["taggable_id", 15], ["taggable_type", "Course"]]
Unpermitted parameters: skill_list
答案 0 :(得分:0)
我找到的解决方案是从模型中移除acts_as_taggable_on :skills
并将:skill_list => []
替换为:tag_list
我想这会失去acts_as_taggable_on的多标签功能,但至少它会让它正常工作