2012-08-27 25 views
2

我使用Rails 3应用程序与devise,simple formhaml宝石。另外我的应用程序支持几个语言环境我在我的主页上创建了简单链接:Rails 3 +设计 - 登录用户无法打开页面来更改密码

%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}") 

另外我评论几行视图/设计/共享/ _links.haml

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

由于我不想让用户注册并查看链接。

回答

5

edit_user_password_path在设计中用于password_controller用于用户需要重置密码的情况。我认为你要找的是edit_user_registration_path。这将让用户编辑registrations_controller的操作,他们可以在其中修改其电子邮件地址和密码。这是默认的设计行为。

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

还要注意,当用户遵循edit_user_registration_path时,可以选择取消他们想要从视图中删除的帐户,或者使用自定义方法来避免这种不需​​要的功能。

+0

这很奇怪。我试图在我的视图中使用'edit_user_registration_path',但Rails生成'未定义的局部变量或方法'edit_user_registration_path'。 – ExiRe

+1

您需要删除该路径的':skip => [:registrations]',或者使用Wiki文章提供的自定义策略。 – janders223

+0

感谢您的通知!! – ExiRe