2014-12-28 30 views
0

我已向我的供应商模型'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列为属性。

然后,我已经把它添加到新的所有者窗体的意见/老板/ 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'。

我必须错过一些东西,但我不知道我要去哪里错......?

回答

0

你一定忘记了在你的控制器中允许那些附加字段的参数。

+0

是的,就是这样。谢谢! – tessad