Adding Custom Fields to Devise Registration - Ruby on Rails 4 & Devise 3 -


hi, have model coach i'm trying add specific fields to. have created migration , added fields registration receive error nomethoderror in devise::registrations#new & undefined method `first_name'

thank taking @ this...
update: have migrated database here code looks far:

registration

sign coach

<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) |f| %>   <%= devise_error_messages! %>     <div><%= f.label :first_name %><br />   <%= f.text_field :first_name, autofocus: true %></div>    <div><%= f.label :email %><br />   <%= f.email_field :email, autofocus: true %></div>    <div><%= f.label :password %><br />     <%= f.password_field :password, autocomplete: "off" %></div>    <div><%= f.label :password_confirmation %><br />     <%= f.password_field :password_confirmation, autocomplete: "off" %></div>    <div><%= f.submit "sign up" %></div> <% end %>  <%= render "coaches/shared/links" %> 

migration

class addfieldstocoaches < activerecord::migration   def change     add_column :users, :first_name, :string     add_column :users, :last_name, :string   end end 

schema

activerecord::schema.define(version: 20140627044906)    create_table "coaches", force: true |t|     t.datetime "created_at"     t.datetime "updated_at"     t.string   "email",                  default: "", null: false     t.string   "encrypted_password",     default: "", null: false     t.string   "reset_password_token"     t.datetime "reset_password_sent_at"     t.datetime "remember_created_at"     t.integer  "sign_in_count",          default: 0,  null: false     t.datetime "current_sign_in_at"     t.datetime "last_sign_in_at"     t.string   "current_sign_in_ip"     t.string   "last_sign_in_ip"   end    add_index "coaches", ["email"], name: "index_coaches_on_email", unique: true   add_index "coaches", ["reset_password_token"], name: "index_coaches_on_reset_password_token", unique: true    create_table "players", force: true |t|     t.datetime "created_at"     t.datetime "updated_at"     t.string   "email",                  default: "", null: false     t.string   "encrypted_password",     default: "", null: false     t.string   "reset_password_token"     t.datetime "reset_password_sent_at"     t.datetime "remember_created_at"     t.integer  "sign_in_count",          default: 0,  null: false     t.datetime "current_sign_in_at"     t.datetime "last_sign_in_at"     t.string   "current_sign_in_ip"     t.string   "last_sign_in_ip"   end    add_index "players", ["email"], name: "index_players_on_email", unique: true   add_index "players", ["reset_password_token"], name: "index_players_on_reset_password_token", unique: true    create_table "users", force: true |t|     t.string   "email",                  default: "", null: false     t.string   "encrypted_password",     default: "", null: false     t.string   "reset_password_token"     t.datetime "reset_password_sent_at"     t.datetime "remember_created_at"     t.integer  "sign_in_count",          default: 0,  null: false     t.datetime "current_sign_in_at"     t.datetime "last_sign_in_at"     t.string   "current_sign_in_ip"     t.string   "last_sign_in_ip"     t.datetime "created_at"     t.datetime "updated_at"   end    add_index "users", ["email"], name: "index_users_on_email", unique: true   add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true  end 

trace

started "/coaches/sign_up" 127.0.0.1 @ 2014-06-27 00:50:41 -0400 processing devise::registrationscontroller#new html   rendered coaches/registrations/new.html.erb within layouts/application (1.7ms) completed 500 internal server error in 6ms  actionview::template::error (undefined method `first_name' #<coach:0x007f9f874d6510>):      5:           6:           7:   <div><%= f.label :first_name %><br />      8:   <%= f.text_field :first_name, autofocus: true %></div>      9:        10:   <div><%= f.label :email %><br />     11:   <%= f.email_field :email, autofocus: true %></div>   app/views/coaches/registrations/new.html.erb:8:in `block in _app_views_coaches_registrations_new_html_erb__1603382164571940584_70161540751300'   app/views/coaches/registrations/new.html.erb:3:in `_app_views_coaches_registrations_new_html_erb__1603382164571940584_70161540751300'     rendered /users/noahreisch/.rvm/gems/ruby-2.1.1/gems/actionpack-4.1.0/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.3ms)   rendered /users/noahreisch/.rvm/gems/ruby-2.1.1/gems/actionpack-4.1.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.9ms)   rendered /users/noahreisch/.rvm/gems/ruby-2.1.1/gems/actionpack-4.1.0/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (9.8ms) 

may problem strong parameters. try add following code application_controller.rb.

class applicationcontroller < actioncontroller::base   before_action :configure_permitted_parameters, if: :devise_controller?    protected    def configure_permitted_parameters     devise_parameter_sanitizer.for(:sign_up) << :first_name   end end 

for more information: https://github.com/plataformatec/devise#strong-parameters


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -