未允许的参数错误

时间:2015-05-11 13:50:20

标签: ruby-on-rails ruby-on-rails-4

我正在尝试在我的应用中添加嵌套表单,但shell显示错误:

Unpermitted parameter: description

有我的模特

class Chart < ActiveRecord::Base
  has_many :descriptions
  accepts_nested_attributes_for :descriptions
end

我的控制器中有很强的参数:

  def chart_params
    params.require(:chart).permit(:title, descriptions_attributes: [:name])
  end

这是我的表格:

= form_for @chart do |f|
  = f.text_field :title
  = f.fields_for :descriptions do |d|
    = d.text_field :name
  = f.submit

我做错了什么?

UPD

我是控制器中的更改表单和操作new

形式

 = form_for @chart do |f|
    = f.text_field :title
    = f.fields_for @descriptions do |d|
      = d.text_field :name
    = f.submit

行动新

  def new
    @chart = Chart.new
    @descriptions = @chart.descriptions.build
  end

1 个答案:

答案 0 :(得分:1)

text_field的名称属性&#39; name&#39;应该是&#39; chart [description_attributes] [name]&#39;。

请查看以下代码段:

= form_for @chart do |f|
  = f.text_field :title
  = f.fields_for :descriptions_attributes, @descriptions do |d|
    = d.text_field :name
  = f.submit

控制器的新操作无需更改。