添加新属性并以rails形式使用它

时间:2014-12-28 09:03:06

标签: ruby-on-rails

我在“source”和“source_other”的供应商模型中添加了一个新列。但是,我为新供应商设置的表单没有正确地使用此属性并将其添加到模型

迁移看起来像:

class AddNewColumnToOwner < ActiveRecord::Migration
  def change
     add_column :owners, :source, :string
     add_column :owners, :source_other, :string
  end
end

我知道迁移工作正常,因为我可以在我的rails控制台中看到所有者确实将source和source_other列为属性。

然后,我已将其添加到新的所有者表单views / owners / new.html.haml:

.field{style: 'padding-bottom:0px;' }
        = f.input :source, as: :select, collection: HOW_HEAR, label: 'How did you hear about us?', allow_blank: false
      .field#other_source_field
        = f.input :source_other, input_html: { class: 'text_field' }, label: 'If other please let us know where you heard about us'

但是,当我填写表单以添加新的所有者并选择其中一个源选项时,它不会将其存储在表中。我知道这一点,因为当我在rails控制台中检查Owner.last时,我可以看到源是'nil',即使我在表单下拉选项中选择了source选项。

我一定错过了什么,但我不确定我哪里出错...?

1 个答案:

答案 0 :(得分:0)

您必须忘记在控制器中允许其他字段的参数。