2013-04-30 41 views
0

为什么我用simple_form和hstore得到'undefined method'?

class User < ActiveRecord::Base 
    attr_accessible :email 

    validates :email, 
    presence: true 

    serialize :data, ActiveRecord::Coders::Hstore 

end 

<%= simple_form_for User.new do |f| %> 
    <%= f.input :email %> 
    <%= f.input :first_name %> 
    <%= f.input :zipcode %> 
    <%= f.button :submit, 'Sign up' %> 
<% end %> 

为什么当我想Sign up我得到一个错误:

undefined method `zipcode' for #<User:0x007fd397631650> 

完全跟踪: https://gist.github.com/3c9df05758ea3d486989

+0

zipcode是'data'散列中的一个属性吗?如果是这样,我不认为你可以以这种方式访问​​它,我怀疑simple_form将处理序列化字段。也许这个线程可以帮助你http://stackoverflow.com/questions/9613208/serialized-hash-field-and-simple-form – 2013-04-30 13:52:10

+0

以及为什么它应该工作? – fotanus 2013-04-30 14:00:00

回答

1

simple_form只能为模型的属性创建输入,并且它看起来像zipcode不是User模型的属性。

您应该运行迁移以将此列添加到Users表中,然后您将能够存储用户的邮政编码。

相关问题