3

私はレールに慣れていないので、登録時に確認メールを追加しようとしています。現在、このエラーが発生しています。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)

4

2 に答える 2

3

問題はあなたにあると思いrake db:migrate ますrake db:migrate

データベースの schema_migrations テーブルを確認し、書き込まれた移行のタイムスタンプが存在するかどうかを確認してください。(time-stamp)_add_email_activation_token_to_users.rb.

于 2013-04-26T16:18:16.907 に答える
3

実行rake db:migrate:statusして、問題の移行が既に実行されているかどうかを確認します。

すでに実行されている場合はrake db:rollback、最後の移行をロールバックします。

add_column :users, :email_activation_token, :boolean, :default => false

実行しますrake db:migrate

チェックしているデータベースが、移行が実行されているデータベースであることを確認してください。

于 2013-04-26T16:14:43.217 に答える