【发布时间】:2013-04-26 15:58:10
【问题描述】:
我是 Rails 新手,我正在尝试在注册时添加电子邮件确认。我目前收到此错误。我尝试了 rake db:migrate 但由于某种原因我无法将 email_activation_token 放入用户表中。我用 sqllightbrowser 查了一下,没有。
我正在使用 Haml,如下所示。
奖励积分:如果您告诉我如何将 email_activation_token 设置为布尔值并使其默认为 false。
Users#create 中的 NoMethodError
#(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
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
app/models/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:回滚 耙分贝:迁移
但现在我的错误不同了
#(#(Class:0xacca7f4):0xa614ef0) 的未定义方法 `edit_email_activation_url'
【问题讨论】:
-
“rake db:migrate”和“cat db/schema.rb”的输出是什么?
-
对不起?那还不清楚。你的意思是我对用户邮件密码重置的看法是什么?
-
如果你去你的终端运行上面的命令,你会得到什么输出/文本?可以贴在这里吗?
标签: ruby-on-rails ruby-on-rails-3 authentication haml