Ruby on rails 未知操作:操作';创建';找不到注册控制器?
我决定制作一个RegistrationController,以便在注册时将用户重定向到特定页面。唯一的问题是用户甚至没有被创建,因为我得到了错误:Ruby on rails 未知操作:操作';创建';找不到注册控制器?,ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-3.1,devise,Ruby On Rails,Ruby,Ruby On Rails 3,Ruby On Rails 3.1,Devise,我决定制作一个RegistrationController,以便在注册时将用户重定向到特定页面。唯一的问题是用户甚至没有被创建,因为我得到了错误: 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): 我的路
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
design\u用于:用户,:控制器=>{:registrations=>“registrations”}
设计范围:用户做什么
获取“/注册”=>“设计/注册#新”
获取“/login”=>“设计/会话#新建”
获取“/注销”=>“设计/会话#销毁”
获取“/帐户设置”=>“设计/注册#编辑”
获取“/忘记密码”=>“设计/密码#新”,:as=>:新用户密码
获取'users',:to=>'pages#home',:as=>:user\u root
结束
类注册控制器<应用程序控制器
受保护的
注册后的def路径(资源)
将\u重定向到启动\u路径
结束
def create用这个试过,但运气不佳。
结束
结束
这是怎么回事?这是如何修复的
更新
我将
create
操作置于protected
之外,但现在我得到了缺少模板注册/create
。删除该操作会将我带回未知操作:创建您的创建方法受保护
,这意味着无法将其路由到
将create
方法移出受保护的方法:
class RegistrationsController < ApplicationController
def create
end
protected
def after_sign_up_path_for(resource)
redirect_to start_path
end
end
类注册控制器
问题似乎出在您设置注册控制器的方式上。如果查看,您将看到以下示例:
class RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
'/an/example/path'
end
end
类注册控制器
请注意,RegistrationController
是从Desive::RegistrationController
继承的,而不是ApplicationController
。这样做是为了让您的自定义控制器从Desive继承所有正确的行为,包括创建
操作。当我这样做时,它会给我缺少的模板注册/创建
。这似乎不正确,因为我使用的是Deave。您通常没有一个模板来执行创建
操作,所以我猜Deave没有提供模板。通常,在成功创建后,您会重定向到显示
或索引
操作。啊,但再进一步调查,似乎缺少创建
操作是一种症状,而不是根本问题。我甚至没有看到这种继承。我还取消了将
重定向到
的功能,因为这会导致双重渲染错误。非常感谢。