Hi, I have a model Coach that I'm trying to add specific fields to. I have created a migration and added the fields to the registration but receive the error
NoMethodError in Devise::Registrations#new & undefined method `first_name' for
Update: I have already migrated the database Here is what my code looks like thus far:
Регистрация
Зарегистрируйтесь как тренер
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |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" %>
Миграция
class AddFieldsToCoaches < ActiveRecord::Migration
def change
add_column :users, :first_name, :string
add_column :users, :last_name, :string
end
end
Схема
ActiveRecord::Schema.define(version: 20140627044906) do
create_table "coaches", force: true do |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 do |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 do |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
Обратный след
Started GET "/coaches/sign_up" for 127.0.0.1 at 2014-06-27 00:50:41 -0400
Processing by Devise::RegistrationsController#new as 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' for #<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)