0

I have

class User < ActiveRecord::Base
  attr_accessible :email

  validates :email,
    presence: true

  serialize :data, ActiveRecord::Coders::Hstore

end

and

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

Why when I want to Sign up I get an error:

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

Full trace: https://gist.github.com/3c9df05758ea3d486989

tomekfranek
  • 6,852
  • 8
  • 45
  • 80
  • Is zipcode an attribute in the `data` hash? If so I don't think you can access it in this manner, and I doubt that simple_form will handle handle the serialized field. Maybe this thread can help you http://stackoverflow.com/questions/9613208/serialized-hash-field-and-simple-form – Wizard of Ogz Apr 30 '13 at 13:52
  • and why it should work? – fotanus Apr 30 '13 at 14:00

1 Answers1

1

simple_form can only create inputs for attributes of a model, and it looks like zipcode is not an attribute of your User model.

You should run a migration to add this column to your Users table, and then you will be able to store the zipcode of a user.

AlexBrand
  • 11,971
  • 20
  • 87
  • 132