我在Devise :: RegistrationsController #creore中遇到此错误NoMethodError,我不知道我是如何修复它的。如果我尝试进行新的注册,服务器加载很长时间,之后我看到这个错误。
我的迁移看起来像这样:
class DeviseCreateRegistrationsControllers < ActiveRecord::Migration
def change
create_table(:registrations_controllers) do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
#t.string :encrypted_password, :null => false, :default => ""
t.database_authenticatable :null => false
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
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
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
t.timestamps null: false
end
add_index :registrations_controllers, :email, unique: true
add_index :registrations_controllers, :reset_password_token, unique: true
# add_index :registrations_controllers, :confirmation_token, unique: true
# add_index :registrations_controllers, :unlock_token, unique: true
end
end
我的注册控制器如下所示:
class RegistrationsController < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
t.string :encrypted_password, :null => false, :default => ""
end
和我的观点/ devise / registration / new.html.erb看起来像这样
<div class="form-container glassy-bg small-10 small-centered medium-8 large-6 columns">
<h2>Register</h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="mb1"><%= f.email_field :email, autofocus: true, placeholder: "Email", class: "radius" %></div>
<div class="mb1"><%= f.password_field :password, autocomplete: "off", placeholder: "Password", class: "radius" %></div>
<div class="mb1"><%= f.password_field :password_confirmation, autocomplete: "off", placeholder: "Confirm password", class: "radius" %></div>
<div><%= f.submit "Let's Go", class: "button" %></div>
<% end %>
<%= render "devise/shared/links" %>
</div>
请帮助,谢谢。
答案 0 :(得分:1)
一切看起来都像是一团糟。 RegistrationsController
应该是模型User
,因为它扩展了ActiveRecord :: Base和那些行:
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
也来自用户模型的设计。
为什么t.string :encrypted_password, :null => false, :default => ""
中有RegistrationsController
(实际上它应该是我上面提到过的模型)?
某处必须是复制粘贴故障。请再次检查整个项目或重新创建新的Rails应用程序,然后从干净的项目中安装Devise。