如何覆盖Devise 1.1.rc2控制器?

时间:2010-07-14 15:59:59

标签: ruby-on-rails ruby devise

我想添加选项以使用JSON格式和其他一些特定内容注册到我的应用程序。我尝试添加自己的RegistrationsController控制器,然后将我的路由设置为:

devise_for :users, :path_names => { :sign_in => 'signin', :sign_out => 'signout', :sign_up => 'signup' }
match 'signin', :to => 'devise/sessions#new', :as => "new_user_session"
match 'signout', :to  => 'devise/sessions#destroy', :as => "destroy_user_session"
match 'signup(.:format)', :to => 'registrations#new', :as => "new_user_registration"

app / controllers / registrations_controller.rb中的RegistrationsController如下所示:

class RegistrationsController < Devise::RegistrationsController
  prepend_view_path "app/views/devise"
  def create
    # My custom implementation
  end
end

无论格式是什么,它总是会抛出以下错误

AbstractController::ActionNotFound (AbstractController::ActionNotFound):
/usr/local/Cellar/Gems/1.8/gems/devise-1.1.rc2/lib/devise/controllers/internal_helpers.rb:57:in `is_devise_resource?'
...

我甚至尝试将注册控制器从git添加到app / controllers / devise / registrations_controller.rb并将路由更改为指向该路由,但这也不起作用。有人有想法吗?

1 个答案:

答案 0 :(得分:1)

想出来!我试图在注册控制器中覆盖create,但没有路由到它...愚蠢的错误。

devise_for :users, :path_names => { :sign_in => 'signin', :sign_out => 'signout', :sign_up => 'signup' }, :controllers => { :registrations => "registrations" }
match 'signin', :to => 'devise/sessions#new', :as => "new_user_session"
match 'signout', :to  => 'devise/sessions#destroy', :as => "destroy_user_session"
get 'signup', :to => 'registrations#new', :as => "new_user_registration"
post 'signup(.:format)', :to => 'registrations#create', :as => "create_user_registration"