加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

编辑
日志文件表示不允许的参数:perspective_id,objective_ids

解决方法

我解决了换线
params.require(:objective).permit(:name,:objective_ids)

params.require(:objective).permit(:name,:objective_ids => [])

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读