2012-11-16 42 views
4

我想禁用重載設計密碼控制器

def create 
    self.resource = resource_class.send_reset_password_instructions(resource_params) 

    if successfully_sent?(resource) 
     respond_with({}, :location => after_sending_reset_password_instructions_path_for(resource_name)) 
    else 
     respond_with(resource) 
    end 
    end 

,所以它不會發送重置密碼

所以經過所有重定向,我創建了一個新的文件下的應用程序/控制器/用戶/所謂passwords_controller.rb

它看起來像這樣

class User::PasswordsController < Devise::PasswordsController 

    def create 
    self.resource = resource_class.send_reset_password_instructions(resource_params) 

      if successfully_sent?(resource) 
      flash[:notice] = "sent password" 
      else 
       respond_with(resource) 
      end 
     end 

     def new 
      super 
     end 

     def update 
      super 

     end 
     def edit 
      super 

     end 
    end 

和改變我的路線

devise_for :users, :controllers => { :invitations => 'users/invitations', :passwords => 'users/passwords' } 

我也有devise_invite寶石..

當我點擊一個鏈接,已忘記的密碼我得到這個錯誤在

Started GET "https://stackoverflow.com/users/password/new" for 127.0.0.1 at 2012-11-16 10:21:07 +0200 

ActionController::RoutingError (uninitialized constant Users::PasswordsController): 

rake routes

   user_password POST /users/password(.:format)     users/passwords#create 
      new_user_password GET /users/password/new(.:format)    users/passwords#new 
     edit_user_password GET /users/password/edit(.:format)    users/passwords#edit 
          PUT /users/password(.:format)     users/passwords#update 

視圖中的鏈接是

<%= link_to "Forgot your password?", new_password_path(User) , :class => "control-group", :style => "position: absolute; bottom: 0", :id=>"forgotpass" %> 

我錯過了什麼?

+0

也許是因爲錯別字 – Thanh

+0

我不明白在哪裏 –

+0

在你的視圖中,將'new_password_path(User)'改爲'new_user_password_path' – Thanh

回答

9

密碼控制器從設計密碼控制器擴展。因此,使用設計密碼控制器來擴展密碼控制器。

class PasswordsController < Devise::PasswordsController 
    ...................... 

end 

變化與色器件

devise_for :users, :controllers => { :passwords => "passwords" } 

和路線密碼控制器的路線將是這樣的: -

user_password  POST /password(.:format)  Passwords#create 

new_user_password GET /password/new(.:format) Passwords#new 

edit_user_password GET /password/edit(.:format) Passwords#edit 
        PUT /password(.:format)  Passwords#update 
+1

是否需要' devise_for:users,:controllers => {:passwords =>「passwords」}'帶小寫字母「p」? –

+0

是的,'{:密碼=>「密碼」}「不起作用。 使用':{:passwords =>「密碼」}' –

1

如果你想保持一個命名空間,嘗試:

# routes.rb 
devise_for :users, controllers: { passwords: 'users/passwords' } 

# users/passwords_controller.rb 
class Users::PasswordsController < Devise::PasswordsController 
    ... 
end