2

Rails 3 アプリケーションをdevisesimple formおよびhamlgems で使用しています。また、私のアプリケーションはいくつかのロケールをサポートしています。ホームページに簡単なリンクを作成しました:

%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/

ユーザーが登録してリンクを表示できるようにしたくないためです。

4

1 に答える 1

5

edit_user_password_pathpassword_controllerユーザーがパスワードをリセットする必要がある場合に、Devise で使用されます。あなたが探しているのはedit_user_registration_path. registrations_controllerこれにより、ユーザーは自分の電子メール アドレスとパスワードを変更できる編集アクションに移動します。これは Devise のデフォルトの動作です。

もう少しカスタムなものを提供したい場合は、カスタムのパスワード変更機能を提供する方法に関するDevise Wikiのチュートリアルを読むことができます。

また、ユーザーがフォローしている場合edit_user_registration_path、ビューから削除したいアカウントをキャンセルするか、カスタム アプローチを使用してこの不要な機能を回避するオプションがあることに注意してください。

于 2012-08-27T12:58:14.037 に答える