ruby-on-rails - 未知操作 : The action 'create' could not be found for RegistrationsController?

标签 ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.1 devise

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

我的路线和 Controller :

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

最佳答案

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

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

class RegistrationsController < ApplicationController

  def create

  end

  protected

  def after_sign_up_path_for(resource)
    redirect_to start_path
  end

end

关于ruby-on-rails - 未知操作 : The action 'create' could not be found for RegistrationsController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11002553/

相关文章:

ruby-on-rails - 使用 javascript 响应 HTML 请求?

sql - Ruby on Rails - 迁移、唯一列和索引(使用数组)

ruby - Microsoft Word 符号的编码问题 [UTF-8 到 ISO-5589-1]

ruby - Haml 将输入元素呈现为转义

ruby-on-rails - Rails Arel 选择不同的列

ruby-on-rails - 为我的 Rails 3 应用程序创建内部分析的最佳方法是什么?

ruby-on-rails - em-mongo 的例子?

ruby-on-rails - 为什么我的测试没有通过?

ruby-on-rails-3 - Rails 3.1 从供应商/ Assets /图像提供图像

ruby-on-rails - 将 vendor/assets/javascripts 添加到我的有效 Assets 路线