def create
@author = User.find(current_user)
pub_params = params[:publication]
##
#bcids = pub_params['categorizations_attributes']['0']['book_category_id']
#pub_params.delete('categorizations_attributes')
#pub_params['categorizations_attributes'] = Hash.new()
#bcids.each_with_index do |i, bcid|
# if i.to_i > 0
# pub_params['categorizations_attributes'][i] = Hash.new()
# pub_params['categorizations_attributes'][i]['book_category_id'] = bcid
# end
#end
@publication = @author.publications.new(pub_params)
#setup_sti_model
respond_to do |format|
if @publication.save
format.html { redirect_to @publication, notice: 'Publication was successfully created.' }
format.json { render json: @publication, status: :created, location: @publication }
else
format.html { render action: "new" }
format.json { render json: @publication.errors, status: :unprocessable_entity }
end
end
end
#PUT / publications / 1 #PUT /publications/1.json
每当我尝试添加新的出版物时,我都会收到此错误。
答案 0 :(得分:2)
答案 1 :(得分:1)
答案 2 :(得分:0)
不要击败死马,但另外两名响应者是正确的。要防止质量分配漏洞,您需要明确说明哪些字段可以进行批量更新。
您还可以使用attr_protected为无法批量更新的字段设置黑名单,但通过attr_accessible列入白名单是首选方法。