gpt4 book ai didi

ruby - Rails 3 + Devise - 登录用户无法打开页面更改密码

转载 作者:数据小太阳 更新时间:2023-10-29 08:33:21 25 4
gpt4 key购买 nike

我将 Rails 3 应用程序与 devisesimple formhaml gem 一起使用。我的应用程序也支持少数语言环境。我在我的主页上创建了一个简单的链接:

%p
= link_to "Change pass", edit_user_password_path

应用程序向所有人显示此链接(只是为了测试)。但我发现非登录用户可以打开此链接。但是,当登录用户打开此链接时,系统会提示:

You are already signed in. 

我不知道我做错了什么。

我的用户模型:

class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
# attr_accessible :title, :body
end

我的路线:

  scope ":locale", locale: /#{I18n.available_locales.join("|")}/ do
devise_for :users, :skip => [:registrations]

root :to => 'pages#home'
end

match '*path', to: redirect("/#{I18n.default_locale}/%{path}"), constraints: lambda { |req| !req.path.starts_with? "/#{I18n.default_locale}/" }
match '', to: redirect("/#{I18n.default_locale}")

我还在 views/devise/shared/_links.haml 中评论了几行

- if devise_mapping.registerable? && controller_name != 'registrations'
/ = link_to t(".sign_up_link"), new_registration_path(resource_name)
/ %br/

因为我不想让用户注册并看到链接。

最佳答案

edit_user_password_path 由 Devise 中的 password_controller 使用,用于当用户需要重置密码时。我认为您正在寻找的是 edit_user_registration_path 。这将使用户编辑 registrations_controller 的操作,他们可以在其中修改他们的电子邮件地址和密码。这是 Devise 的默认行为。

如果您想提供更多自定义内容,可以阅读 Devise Wiki 上的教程。关于如何提供自定义密码更改功能。

另请注意,当用户遵循 edit_user_registration_path 时,他们可以选择取消您可能希望从 View 中删除的帐户,或使用自定义方法来避免这种不需​​要的功能.

关于ruby - Rails 3 + Devise - 登录用户无法打开页面更改密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12142026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com