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
zipcode是'data'散列中的一個屬性嗎?如果是這樣,我不認爲你可以以這種方式訪問它,我懷疑simple_form將處理序列化字段。也許這個線程可以幫助你http://stackoverflow.com/questions/9613208/serialized-hash-field-and-simple-form – 2013-04-30 13:52:10
以及爲什麼它應該工作? – fotanus 2013-04-30 14:00:00