0

我有一个使用 2 类角色的应用程序:用户和管理员。对于用户,我已经覆盖了RegistrationControllerandPasswordsController但是在添加了PasswordsController管理员的登录页面(不同于用户,这是自定义的)之后,会出现以下路由错误:

Routing Error

No route matches {:action=>"create", :controller=>"password_resets", :locale=>:admin}

这是我的 routes.rb 文件:

AppName::Application.routes.draw do

  devise_for :admin

  namespace :backend do
    root :to => "home#index"

    resources :exchanges, :except => :show
    resources :prices, :except => :show
    resources :offers
    resources :newss
    resources :users, :except => :show

  scope ':locale', :locale => /en|ro/ do

    namespace :profile do
      root :to => 'home#index'
      resources :orders  do
        resources :items
      end
    end


    devise_for :users, :skip => [:sessions, :registrations, :passwords]

    devise_scope :user do
      get 'logare' => 'registrations#logare', :as => :new_user_session
      post 'logare' => 'devise/sessions#create', :as => :user_session
      delete 'index' => 'devise/sessions#destroy', :as => :destroy_user_session
      get 'inregistrare' => 'registrations#new', :as => :new_user_registration
      post 'inregistrare' => 'registrations#create', :as => :user_registration
      get 'get_city_list' => 'registrations#get_city_list', :as => :get_city_list
      get 'edit' => 'registrations#edit', :as => :user_edit
      post 'edit' => 'registrations#update', :as => :user_update
      get 'new_password' => 'password_resets#new', :as => :password_reset
      post 'new_password' => 'password_resets#create', :as => :new_password
      get 'edit_password' => 'password_resets#edit', :as => :edit_password_reset
      post 'edit_password' => 'password_resets#update', :as => :update_password
    end

  end

  match '/:locale' => 'home#index'
  root :to => 'Home#index'

  match '*a', :to => 'errors#routing'
end

但正如我所说,这个 url /admin/sign_in 给出了提到的路由错误。

不知道我错过了什么。如果我删除PasswordsController,一切都会再次起作用。

PS:这里是PasswordResetsController

class PasswordResetsController < ApplicationController
  def new

  end

  def create
    user = User.find_by_email(params[:email])
    user.send_password_reset if user
    redirect_to new_user_session_path, :notice => t('password_reset_notice')
  end

  def edit
    @user = User.find_by_reset_password_token!(params[:reset_token])
  end

  def update
    @errors_user = nil
    @user = User.find_by_reset_password_token!(params[:token])
    if @user
      if @user.reset_password_sent_at < 2.hours.ago
        redirect_to password_reset_path, :alert => t('password_expired')
      else
        @user.password = params[:user][:password]
        @user.password_confirmation = params[:user][:password_confirmation]
        unless @user.save
          @errors_user = @user.errors.full_messages.join(';<br/>') + '.'
        end
        unless @errors_user.nil?
          @reset_token = params[:token]
          render :edit
        else
          redirect_to new_user_session_path, :notice => t('password_change_success')
        end
      end
    end
  end
end

我的登录表单(对于用户,对于管理员,我使用标准设计):

<div class='signin-container'>
<%= form_for(:user, :url => user_session_path(@user)) do |f| %>
    <%= f.label :email, 'Email:', :id => 'username_label', :class => 'general-signin' %>
    <%= f.text_field :email, :id => 'username-field', :class => 'general-signin' %>

    <%= f.label :password, t('inregistrare.parola'), :id => 'pass_label', :class => 'general-signin' %>
    <%= f.password_field :password, :size => 23, :id => 'pass-field', :class => 'general-signin' %>
    <%= f.check_box :remember_me, :id => 'remember' %>
    <%= f.label :remember_me, :id => 'remember-label' %>
    <%= f.submit "", :class => 'general-signin', :id => 'buton-signin' %>
<% end %>
<a href=<%= new_user_registration_path %>><span class='creeaza'><%= t('logare.creeaza') %></span></a>
<a href=<%= password_reset_path %>><span class='forgot-pass'><%= t('forgot_password') %></span></a>
</div>
4

1 回答 1

1

figured it out ... had to generate the devise views and edit shared/_links.erb

<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />

became

<%= link_to "Forgot your password?", new_password_path(:locale => I18n.locale) %><br />
于 2013-07-18T12:51:34.367 回答