I'm attempting to add a full_name
field/column to my User model (using the devise
gem) and Rails 4.
Most of the examples online recommend using attr_accessible, but it sounds like this should be approached differently in Rails 4.
How would I add full_name
to my User model? I've been able to successfully run the migration.
File: Migration > add_full_name_to_users
class AddFullNameToUsers < ActiveRecord::Migration
def change
add_column :users, :full_name, :string
end
end
File: Registration > app/views/devise/registration/new.html
.
.
.
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<%= f.label :full_name %>
<%= f.text_field :full_name, :autofocus => true %>
<%= f.label :email %>
<%= f.email_field :email %>
.
.
.
Once your model has its full_name attribute, you will have to configure permitted parameters for the #sign_up and #account_update Devise actions.
This solution should work, working with sign_up and update:
From devise documentation:
You should check the url below to find the approach that will best fit your needs: https://github.com/plataformatec/devise#strong-parameters
Enable Strong Parameters for Devise instead of attr_accessible. To do so, create a new initiliazer with that content: