导轨中不允许的参数4 [英] Unpermitted parameters in rails 4
本文介绍了导轨中不允许的参数4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我阅读了 collection_check_boxes
,但我不明白如何设置选中的值。
我有以下模型:
class Objective< ActiveRecord :: Base
has_many:indicators
has_many:objective_children,class_name:Objective,foreign_key:parent_id
def objective_ids
objective_children。 collect {| o | o.id}
end
def objective_ids = objectives_ids
objectives_ids.each do | id |
objective_children<< Objective.find(id)
end
end
end
编辑视图:
<%= form_for(@objective)do | f | %>
<%= f.collection_check_boxes:objective_ids,Objective.all,:id,:name%>
<%= f.submit%>
<%end%>
html复选框都可以,但我不知道如何将值设置为 objective
。我被尝试定义 objective_ids = objectives_ids
但没有发生任何事。
在控制器:
class ObjectivesController< ApplicationController
def objective_params
params.require(:objective).permit(:name,:code,:description,:objective_ids)
end
end
EDIT
日志文件说未授权的参数:perspective_id,objective_ids
解决方案我解决了更改行
params.require(:objective).permit(:name,:code,:description,:objective_ids)
到
params.require(:objective).permit :code,:description,:objective_ids => [])
I read about
collection_check_boxes
but I don't understand how can I set the checked values. I have the following model:class Objective < ActiveRecord::Base has_many :indicators has_many :objective_children, class_name: "Objective", foreign_key: "parent_id" def objective_ids objective_children.collect{|o| o.id} end def objective_ids= objectives_ids objectives_ids.each do |id| objective_children << Objective.find(id) end end end
edit view:
<%= form_for(@objective) do |f| %> <%= f.collection_check_boxes :objective_ids, Objective.all, :id, :name %> <%= f.submit %> <% end %>
the html checkbox are ok but I don't know how to set the values to
objective
. I was tried defineobjective_ids= objectives_ids
but nothing happens.In Controller:
class ObjectivesController < ApplicationController def objective_params params.require(:objective).permit(:name, :code, :description, :objective_ids) end end
EDIT The log file says
Unpermitted parameters: perspective_id, objective_ids
解决方案I solved changing the line
params.require(:objective).permit(:name, :code, :description, :objective_ids)
to
params.require(:objective).permit(:name, :code, :description, :objective_ids => [])
这篇关于导轨中不允许的参数4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文