Exi*_*iRe 2 ruby haml devise simple-form ruby-on-rails-3.2
我用的Rails 3应用程序devise,simple form和haml宝石.我的应用程序也支持少数语言环境.我在我的主页上创建了简单的链接:
%p
= link_to "Change pass", edit_user_password_path
Run Code Online (Sandbox Code Playgroud)
应用程序为每个人显示此链接(只是为了测试它).但我发现非登录用户可以打开此链接.但是当登录用户打开此链接时,系统会告诉:
You are already signed in.
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚我做错了什么.
我的用户型号:
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
Run Code Online (Sandbox Code Playgroud)
我的路线:
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}")
Run Code Online (Sandbox Code Playgroud)
另外,我在views/devise/shared/_links.haml中评论了几行
- if devise_mapping.registerable? && controller_name != 'registrations'
/ = link_to t(".sign_up_link"), new_registration_path(resource_name)
/ %br/
Run Code Online (Sandbox Code Playgroud)
因为我不想让用户注册并看到链接.
edit_user_password_pathpassword_controller当用户需要重置密码时,由Devise 使用.我想你要找的是edit_user_registration_path.这将使用户可以编辑registrations_controller他们可以修改其电子邮件地址和密码的操作.这是默认的Devise行为.
如果您想提供更多自定义内容,可以阅读Devise Wiki上有关如何提供自定义密码更改功能的教程.
另请注意,当用户跟随时edit_user_registration_path,可以选择取消他们可能要从视图中删除的帐户,或使用自定义方法来避免此不需要的功能.
| 归档时间: |
|
| 查看次数: |
1434 次 |
| 最近记录: |