ruby-on-rails – 导轨中未提供的参数4
发布时间:2020-12-16 20:44:16 所属栏目:百科 来源:网络整理
导读:我阅读了关于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
我阅读了关于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_ids = targets_ids但没有发生任何事情. 控制器: class ObjectivesController < ApplicationController def objective_params params.require(:objective).permit(:name,:code,:description,:objective_ids) end end 编辑 解决方法
我解决了换线
params.require(:objective).permit(:name,:objective_ids) 至 params.require(:objective).permit(:name,:objective_ids => []) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- c# – 加入ASP.NET网站的查询字符串
- ruby-on-rails – 在process_action回调之前:authenticate
- ALTER TABLE 失败,因为下列 SET 选项的设置不正确:'AR
- UT TDD and others
- 调试声明失败. C矢量下标超出范围
- EXT核心API详解(十一)_Ext.data.Store/GroupingStore/JsonS
- ruby-on-rails – Rails – 使用paypal-recurring gem处理P
- Flex根据后台的数据自动生成AdvancedDataGrid
- Flex 布局教程:语法篇
- 在C中编写一个返回布尔值的函数