我正在阅读Hartl教程中的rails并遇到了一个我无法弄清楚的路障。我是生成集成测试(Rspec)的第一步。我进入了:
rails generate integration_test static_pages
然后得到
Waymond-MacBook-Pro:sample_app wayway$ rails generate integration_test static_pages
/Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/mapper.rb:229:in `default_controller_and_action': missing :controller (ArgumentError)
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/mapper.rb:116:in `normalize_options!'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/mapper.rb:64:in `initialize'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/mapper.rb:1443:in `new'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/mapper.rb:1443:in `add_route'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/mapper.rb:1422:in `decomposed_match'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/mapper.rb:1403:in `block in match'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/mapper.rb:1394:in `each'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/mapper.rb:1394:in `match'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/mapper.rb:601:in `map_method'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/mapper.rb:562:in `get'
from /Users/waystylez1/rails_projects/sample_app/config/routes.rb:2:in `block in <top (required)>'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/route_set.rb:341:in `instance_exec'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/route_set.rb:341:in `eval_block'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/route_set.rb:319:in `draw'
from /Users/waystylez1/rails_projects/sample_app/config/routes.rb:1:in `<top (required)>'
from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:223:in `load'
from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:223:in `block in load'
from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:214:in `load_dependency'
from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:223:in `load'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:40:in `each'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:40:in `load_paths'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:16:in `reload!'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:26:in `block in updater'
from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/file_update_checker.rb:75:in `call'
from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/file_update_checker.rb:75:in `execute'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:27:in `updater'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:6:in `execute_if_updated'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/initializable.rb:30:in `instance_exec'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/initializable.rb:30:in `run'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/initializable.rb:55:in `block in run_initializers'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:180:in `each'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/initializable.rb:54:in `run_initializers'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/application.rb:215:in `initialize!'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/waystylez1/rails_projects/sample_app/config/environment.rb:5:in `<top (required)>'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/application.rb:189:in `require'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/application.rb:189:in `require_environment!'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/commands.rb:44:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
并且应该在spec / requests目录中获取static_pages_spec.rb。它不在那里所以我猜我的路由错了?任何帮助表示赞赏!谢谢!
修改。这是来自config / routes.rb
SampleApp::Application.routes.draw do
get "static_pages/..."
get "static_pages/home"
get "static_pages/help"
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
# root 'welcome#index'
# Example of regular route:
# get 'products/:id' => 'catalog#view'
# Example of named route that can be invoked with purchase_url(id: product.id)
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
# Example resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Example resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Example resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Example resource route with more complex sub-resources:
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', on: :collection
# end
# end
# Example resource route with concerns:
# concern :toggleable do
# post 'toggle'
# end
# resources :posts, concerns: :toggleable
# resources :photos, concerns: :toggleable
# Example resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
end
答案 0 :(得分:0)
您的config/routes.rb
文件有一个小错误:
SampleApp::Application.routes.draw do
# Get rid of this line, as it's not valid
# get "static_pages/..."
get "static_pages/home"
get "static_pages/help"
end
似乎Hartl教程有这样的一行:
$ rails generate controller static_pages ...
http://ruby.railstutorial.org/chapters/static-pages#code-generating_pages
那些额外的点是多余的。您可以使用该空格生成help
或home
操作。例如:
$ rails generate controller static_pages help home