2017-05-09 61 views
1

我正在运行Rails 5.1和Devise 4.2.1。Rails设计确认不要重定向到确认

我已经配置设计可证实: 类用户<的ActiveRecord :: Base的 色器件:database_authenticatable,:登记的,:可证实, :采,:rememberable,:可追踪的,:可验证

我已经设置了路线: devise_for:用户

我已经生成了视图,并自定义了注册和确认。

我也生成了控制器,但没有对这些控制器进行定制,也没有在路径中引用它们。 类ApplicationController中<的ActionController :: Base的 #Login用户 before_action:的authenticate_user

我在我的应用程序控制器设置authendicate用户!

当用户注册,他将被重定向并没有登录确认/ new.html.erb

我在做什么错?

+0

这是正确的行为。确认/新建用于重新发送确认邮件,并且在注册后您不需要该页面,因为注册过程本身会发送确认电子邮件。只有当用户点击“重新发送确认电子邮件”链接时才应该访问该新页面。 – Sajan

+0

嗨@Sajan - 这是正确的行为? 它永远不会告诉用户电子邮件需要确认。它只是重定向登录,并带有警报 - “您需要登录...” –

回答

1

按照以下链接正确提到的所有步骤:

https://github.com/plataformatec/devise/wiki/How-To:-Add-:confirmable-to-Users

修改用户模型

首先,添加设计:confirmablemodels/user.rb文件

创建一个新的迁移

然后,执行迁移:

rails g migration add_confirmable_to_devise 

将生成db/migrate/YYYYMMDDxxx_add_confirmable_to_devise.rb.将以下内容添加到它以执行迁移。

class AddConfirmableToDevise < ActiveRecord::Migration 
# Note: You can't use change, as User.update_all will fail in the down migration 
    def up 
    add_column :users, :confirmation_token, :string 
    add_column :users, :confirmed_at, :datetime 
    add_column :users, :confirmation_sent_at, :datetime 
    # add_column :users, :unconfirmed_email, :string # Only if using reconfirmable 
    add_index :users, :confirmation_token, unique: true 
    # User.reset_column_information # Need for some types of updates, but not for update_all. 
    # To avoid a short time window between running the migration and updating all existing 
    # users as confirmed, do the following 
    execute("UPDATE users SET confirmed_at = NOW()") 
    # All existing user accounts should be able to log in after this. 
    # Remind: Rails using SQLite as default. And SQLite has no such function :NOW. 
    # Use :date('now') instead of :NOW when using SQLite. 
    # => execute("UPDATE users SET confirmed_at = date('now')") 
    # Or => User.all.update_all confirmed_at: Time.now 
    end 

    def down 
    remove_columns :users, :confirmation_token, :confirmed_at, :confirmation_sent_at 
    # remove_columns :users, :unconfirmed_email # Only if using reconfirmable 
    end 
end 

您还可以生成相应的设计意见,如果他们尚未建立:

rails generate devise:views users 

进行迁移rake db:migrate

重新启动服务器。

+0

尽管此链接可能回答此问题,但最好在此处包含答案的基本部分,并提供供参考的链接。如果链接页面更改,则仅链接答案可能会失效。 - [来自评论](/ review/low-quality-posts/16071864) – Jolta

+1

@Jolta新增必备零件。 – puneet18

+0

感谢您的回复,但我已多次阅读文档;-)我希望Devise告诉用户已发送电子邮件以确认其电子邮件地址。我需要在注册路径后添加自定义,然后为此创建我自己的页面吗? –