私はレールに慣れていないので、登録時に確認メールを追加しようとしています。現在、このエラーが発生しています。rake db:migrate を試しましたが、何らかの理由で email_activation_token をユーザー テーブルに取得できません。sqllightbrowser で確認しましたが、そこにはありません。
以下に示すように、私は Haml を使用しています。
ボーナスポイント:email_activation_tokenをブール値に設定し、デフォルトをfalseにする方法を教えていただければ。
ユーザーの NoMethodError#create
#(User:0xa2e96cc) の未定義のメソッド `email_activation_token'
抽出されたソース (3 行目あたり):
3: = edit_email_activation_url(@user.email_activation_token)
私は無駄にこれを試しました
$ rails generate migration add_email_activation_token_to_users
app/db/migrate/(文字列)_add_email_activation_token_to_users.rb
class AddEmailActivationTokenToUsers < ActiveRecord::Migration
def change
add_column :users, :email_activation_token, :string
end
end
app/config/routes.rb
SomeApp::Application.routes.draw do
get "password_resets/new"
get "sessions/new"
resources :users
resources :sessions
resources :password_resets
get "static_pages/home"
get "static_pages/help"
root to: 'static_pages#home'
match "sign_up", to: "users#new"
match '/help', to: 'static_pages#help'
match '/log_in', to: 'sessions#new'
match '/log_out', to: 'sessions#destroy'
end
アプリ/モデル/user.rb
class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation
attr_accessor :password
before_save :encrypt_password
before_save { |user| user.email = email.downcase }
before_create { generate_token(:auth_token) }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
VALID_PASSWORD_REGEX = /^(?=.*[a-zA-Z])(?=.*[0-9]).{6,}$/
validates_confirmation_of :password
validates :password, :on => :create, presence: true, format: { with: VALID_PASSWORD_REGEX }
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false }
更新を編集
経由でデータベースに取得しました
rake db:ロールバック rake db:migrate
しかし、今私のエラーは異なります
未定義のメソッド `edit_email_activation_url' for #(#(Class:0xacca7f4):0xa614ef0)