Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise... additional columns to User model not validating

I am using Devise for authentication in a Rails 3 app. I added first_name and last_name columns to the database via db:migrate. The registration form was modified like so:

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
  <%= devise_error_messages! %>

  <p><%= f.label :first_name %><br />
  <%= f.text_field :first_name %></p>

  <p><%= f.label :last_name %><br />
  <%= f.text_field :last_name %></p>

  <p><%= f.label :email %><br />
  <%= f.text_field :email %></p>

  <p><%= f.label :password %><br />
  <%= f.password_field :password %></p>

  <p><%= f.label :password_confirmation %><br />
  <%= f.password_field :password_confirmation %></p>

  <p><%= f.submit "Sign up" %></p>
<% end %>

Validation in the User model:

  validates :first_name, :last_name, :email, :password, :password_confirmation, :presence => true

For some reason I am getting "First name can't be blank" and "Last name can't be blank" validation errors. It is interesting to note that these are the two fields added in addition to the stock Devise fields. Does Devise prevent adding other fields to the User model? What other reason could there be?

Thanks.

like image 729
Jay Avatar asked Apr 18 '26 21:04

Jay


1 Answers

Probably your user model has defined attr_accessible. if this is true then you have to add :first_name and :last_name to the list.

like image 121
Ireneusz Skrobis Avatar answered Apr 21 '26 13:04

Ireneusz Skrobis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!