这是Node#update
的参数:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"F1HGLeI9E=", "node"=>{"name"=>"Lesty", "parents"=>["13", "35", ""], "family_tree_id"=>"2"}, "commit"=>"Update Node", "id"=>"38"}
这是我的NodesController
:
private
def node_params
params.require(:node).permit(:user_id, :family_tree_id, :name, :description, :parent_id, :parent, :parents)
end
但是当我尝试更新产生上述日志的@node
对象时,我收到此错误:
Node Load (1.1ms) SELECT "nodes".* FROM "nodes" WHERE "nodes"."id" = $1 LIMIT 1 [["id", 38]]
Unpermitted parameters: parents
(1.7ms) BEGIN
(1.3ms) COMMIT
Redirected to http://localhost:3000/nodes/38
Completed 302 Found in 21ms (ActiveRecord: 4.0ms)
请务必注意,parents
对象的@node
属性是通过gem ancestry
继承的,而不是直接在Node
模型上或通过关联继承的。{ / p>
思想?
答案 0 :(得分:2)
如果我没记错的话,你需要告诉strong_parameters预期数组。
def node_params
params.require(:node).permit(:user_id, :family_tree_id, :name, :description, :parent_id, :parent, parents: [])
end
答案 1 :(得分:1)
你可以试试这个
private
def node_params
params.require(:node).permit(:name, :family_tree_id, parents: [])
end