Lea*_*RoR 2 ruby ruby-on-rails devise ruby-on-rails-3 ruby-on-rails-3.1
我决定创建一个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):
Run Code Online (Sandbox Code Playgroud)
我的路线和控制器:
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
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?这是如何解决的?
UPDATE
我把create动作放在了外面,protected但现在我得到了一个Missing template registrations/create.删除动作让我回到了Unknown action: create.
您的create方法是protected,意味着它无法路由到.
将您的create方法移出您的protected方法:
class RegistrationsController < ApplicationController
def create
end
protected
def after_sign_up_path_for(resource)
redirect_to start_path
end
end
Run Code Online (Sandbox Code Playgroud)
看起来问题在于你的设置方式RegistrationsController.如果您看一下Devise wiki页面,解释如何执行此操作,您将看到以下示例:
class RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
'/an/example/path'
end
end
Run Code Online (Sandbox Code Playgroud)
请注意,它RegistrationsController是继承Devise::RegistrationsController而不是ApplicationController.这样做是为了让您的自定义控制器继承Devise中的所有正确行为,包括create操作.