我是 Rails 新手,我正在尝试在注册时添加电子邮件确认。我目前收到此错误。我尝试了 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 生成迁移 add_email_activation_token_to_users
app/db/migrate/(string)_add_email_activation_token_to_users.rb
class AddEmailActivationTokenToUsers < ActiveRecord::Migration
def change
add_column :users, :email_activation_token, :string
end
end
应用程序/配置/路由.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
但现在我的错误不同了
#(#(Class:0xacca7f4):0xa614ef0) 的未定义方法“edit_email_activation_url”