2

我决定制作一个 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.

4

2 回答 2

6

你的create方法是protected,这意味着它不能被路由到。

将您的create方法移出您的protected方法:

class RegistrationsController < ApplicationController

  def create

  end

  protected

  def after_sign_up_path_for(resource)
    redirect_to start_path
  end

end
于 2012-06-12T20:31:50.290 回答
5

看起来问题出在您设置RegistrationsController. 如果您查看解释如何执行此操作的设计 wiki 页面,您将看到以下示例:

class RegistrationsController < Devise::RegistrationsController
  protected

  def after_sign_up_path_for(resource)
    '/an/example/path'
  end
end

请注意,RegistrationsController继承自Devise::RegistrationsController而不是ApplicationController。这样做是为了让您的自定义控制器从 Devise 继承所有正确的行为,包括create操作。

于 2012-06-12T21:07:29.377 回答