我决定注册一个registrationscontroller,这样我就可以在注册时将用户重定向到一个特定的页面。唯一的问题是用户甚至没有被创建,因为我得到了错误:
Started POST "/users" for 127.0.0.1 at 2012-06-12 14:01:22 -0400
AbstractController::ActionNotFound (The action 'create' could not be found for R
egistrationsController):
我的路线和控制器:
devise_for :users, :controllers => { :registrations => "registrations" }
devise_scope :user do
get "/sign_up" => "devise/registrations#new"
get "/login" => "devise/sessions#new"
get "/log_out" => "devise/sessions#destroy"
get "/account_settings" => "devise/registrations#edit"
get "/forgot_password" => "devise/passwords#new", :as => :new_user_password
get 'users', :to => 'pages#home', :as => :user_root
end
class RegistrationsController < ApplicationController
protected
def after_sign_up_path_for(resource)
redirect_to start_path
end
def create # tried it with this but no luck.
end
end
怎么回事?这是怎么解决的?
更新
我把
create
动作放在protected
之外,但现在得到Missing template registrations/create
。删除该操作将使我返回Unknown action: create
。 最佳答案
看起来问题在于设置RegistrationsController
的方式。如果您查看the Devise wiki page explaining how to do this,您将看到以下示例:
class RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
'/an/example/path'
end
end
注意
RegistrationsController
是从Devise::RegistrationsController
继承的,而不是从ApplicationController
继承的。这样做的目的是让您的自定义控制器从designe继承所有正确的行为,包括create
操作。