1

使用devise與Rails 3應用程序,我已閱讀關於如何自定義註冊後路線的wiki/docs,我使用可確認的模塊,所以我認爲我需要覆蓋after_inactive_sign_up_path_forRails 3/devise似乎忽略了自定義控制器

我想我已經做得很好,但它完全忽略了我的自定義控制器,並且在註冊後仍然路由到root_path。使我抓狂。

我的註冊使用的是用戶模型,我已經使用生成任務複製了設計的視圖;如果我將它們移動到的意見/註冊設計回落到默認視圖(在我猜的寶石),所以它似乎並沒有被「注意到」我的控制器

我有這個在我的路線:

devise_for :users, :controllers => { :registrations => "registrations" } 
match 'sign_up_done' => 'home#sign_up_done', :as => :after_sign_up 

這裏是我的控制器:(控制器/ registrations_controller.rb)

class RegistrationsController < Devise::RegistrationsController 
    def after_inactive_sign_up_path_for(resource) 
    after_sign_up_path 
    end 
    def after_sign_up_path_for(resource) 
    after_sign_up_path 
    end 
end 

(由after_sign_up_path_for以防萬一,使用可證實)

它只是似乎併發症完全忽略我的控制器,命名是否錯誤? 感謝您的任何意見!

回答

0

我認爲你的文件夾結構可能有問題。試試這個結構:(這是相同的寶石文件夾)

app/controllers/devise/registrations_controller.rb 
app/views/devise/registrations/new.html.erb 
app/views/devise/registrations/edit.html.erb 

和控制器文件看起來是一樣的,因爲它是在創業板夾聲明:

#app/controllers/devise/registrations_controller.rb 

# NOT: class RegistrationsController < Devise::RegistrationsController , 
# since you are "overwriting" it. 
class Devise::RegistrationsController < DeviseController 

    def after_inactive_sign_up_path_for(resource) 
    #... 
    end 
end 
+0

在此設置下,我得到:預期.../app/controllers/devise/registrations_controller.rb來定義Devise :: RegistrationsController – bobomoreno 2012-03-20 17:28:01

+0

我更新了我的答案 – 2012-03-20 23:39:05

+0

我最終發現我的路線文件中有一個重複行:「devise_for:users」,這是第一行由發電機添加;我沒有看到它,因爲我的觀點是滾動的,顯然在路線較高的線覆蓋較低的路線。這就是爲什麼它忽略了我的自定義控制器,因爲它是在下面一行中定義的。 – bobomoreno 2012-03-24 21:36:18