【发布时间】:2015-11-20 08:20:14
【问题描述】:
我在 Devise::RegistrationsController#create 中遇到了这个错误 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
我的views/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>
请帮忙,谢谢。
【问题讨论】:
标签: ruby-on-rails ruby devise registration user-registration