以下是我所面临的文件内容和错误跟踪。 导致此错误的代码行位于routes.rb
中match 'users/set_up_details' => 'registrations#initialize_user_details', :via => post
在我的项目中定义的控制器
controllers
├── application_controller.rb
├── confirmations_controller.rb
├── notes_controller.rb
└── registrations_controller.rb
registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
prepend_before_filter :require_no_authentication, only: [ :initialize_user_details, :new, :create, :cancel ]
prepend_before_filter :authenticate_scope!, only: [:edit, :update, :destroy ]
def initialize_user_details
# blah blah.....
end
end
的routes.rb
NoteApp::Application.routes.draw do
#match 'users/sign_up' => 'registrations#new'
#match 'users' => 'registrations#create', :via => post
#resources :registrations
devise_for :users, :controllers => {
:confirmations => "confirmations",
:registrations => "registrations"
}
devise_scope :user do
authenticated do
root to: 'notes#index'
end
unauthenticated do
root to: 'devise/sessions#new'
end
end
match 'users/set_up_details' => 'registrations#initialize_user_details', :via => post # error caused by this line
resources :notes
# The priority is based upon order of creation:
# first created -> highest priority.
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Sample resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Sample resource route with more complex sub-resources
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', :on => :collection
# end
# end
# Sample resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => 'welcome#index'
# See how all your routes lay out with "rake routes"
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id))(.:format)'
end
rake routes命令错误跟踪
>rake routes --trace
** Invoke routes (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
ArgumentError: missing :controller
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/actionpack-3.2.18/lib/action_dispatch/routing/mapper.rb:174:in `default_controller_and_action'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/actionpack-3.2.18/lib/action_dispatch/routing/mapper.rb:71:in `normalize_options!'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/actionpack-3.2.18/lib/action_dispatch/routing/mapper.rb:61:in `initialize'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/actionpack-3.2.18/lib/action_dispatch/routing/mapper.rb:1315:in `new'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/actionpack-3.2.18/lib/action_dispatch/routing/mapper.rb:1315:in `add_route'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/actionpack-3.2.18/lib/action_dispatch/routing/mapper.rb:1294:in `decomposed_match'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/actionpack-3.2.18/lib/action_dispatch/routing/mapper.rb:1276:in `block in match'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/actionpack-3.2.18/lib/action_dispatch/routing/mapper.rb:1276:in `each'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/actionpack-3.2.18/lib/action_dispatch/routing/mapper.rb:1276:in `match'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/actionpack-3.2.18/lib/action_dispatch/routing/mapper.rb:500:in `map_method'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/actionpack-3.2.18/lib/action_dispatch/routing/mapper.rb:472:in `post'
/home/himanshu_office/projects/ruby_projects/note_app/config/routes.rb:17:in `block in <top (required)>'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/actionpack-3.2.18/lib/action_dispatch/routing/route_set.rb:285:in `instance_exec'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/actionpack-3.2.18/lib/action_dispatch/routing/route_set.rb:285:in `eval_block'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/actionpack-3.2.18/lib/action_dispatch/routing/route_set.rb:263:in `draw'
/home/himanshu_office/projects/ruby_projects/note_app/config/routes.rb:1:in `<top (required)>'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:245:in `load'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:245:in `block in load'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:236:in `load_dependency'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:245:in `load'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/railties-3.2.18/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/railties-3.2.18/lib/rails/application/routes_reloader.rb:40:in `each'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/railties-3.2.18/lib/rails/application/routes_reloader.rb:40:in `load_paths'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/railties-3.2.18/lib/rails/application/routes_reloader.rb:16:in `reload!'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/railties-3.2.18/lib/rails/application/routes_reloader.rb:26:in `block in updater'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/activesupport-3.2.18/lib/active_support/file_update_checker.rb:78:in `call'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/activesupport-3.2.18/lib/active_support/file_update_checker.rb:78:in `execute'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/railties-3.2.18/lib/rails/application/routes_reloader.rb:27:in `updater'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/railties-3.2.18/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/railties-3.2.18/lib/rails/application/finisher.rb:66:in `block in <module:Finisher>'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/railties-3.2.18/lib/rails/initializable.rb:30:in `instance_exec'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/railties-3.2.18/lib/rails/initializable.rb:30:in `run'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/railties-3.2.18/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/railties-3.2.18/lib/rails/initializable.rb:54:in `each'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/railties-3.2.18/lib/rails/initializable.rb:54:in `run_initializers'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/railties-3.2.18/lib/rails/application.rb:136:in `initialize!'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/railties-3.2.18/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/himanshu_office/projects/ruby_projects/note_app/config/environment.rb:5:in `<top (required)>'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:251:in `require'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:251:in `block in require'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:236:in `load_dependency'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:251:in `require'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/railties-3.2.18/lib/rails/application.rb:103:in `require_environment!'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/railties-3.2.18/lib/rails/application.rb:305:in `block (2 levels) in initialize_tasks'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/lib/rake/task.rb:240:in `call'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/lib/rake/task.rb:235:in `each'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/home/himanshu_office/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/lib/rake/task.rb:201:in `block in invoke_prerequisites'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/lib/rake/task.rb:199:in `each'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/lib/rake/task.rb:199:in `invoke_prerequisites'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/lib/rake/task.rb:178:in `block in invoke_with_call_chain'
/home/himanshu_office/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/lib/rake/application.rb:106:in `each'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/bin/rake:33:in `<top (required)>'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/bin/rake:23:in `load'
/home/himanshu_office/.rvm/gems/ruby-2.1.5/bin/rake:23:in `<main>'
Tasks: TOP => routes => environment
答案 0 :(得分:0)
因为我超越了Devise控制器。我需要按如下方式定义路线:
devise_scope :user do
post 'users/set_up_details' => 'registrations#initialize_user_details'
end
解决方案参考: Adding new action to devise registrations_controller