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。これを行う方法を説明している Devise wiki ページを見ると、次の例が表示されます。

class RegistrationsController < Devise::RegistrationsController
  protected

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

はではなくRegistrationsControllerから継承していることに注意してください。これは、カスタム コントローラーがアクションを含むすべての正しい動作を Devise から継承するようにするためです。Devise::RegistrationsControllerApplicationControllercreate

于 2012-06-12T21:07:29.377 に答える