0

rb文件代码

SampleApp::Application.routes.draw do
  get "static_pages/home"


match '/help' to:'static_pages#help'
match '/about' to:'static_pages#about'
match '/contact' to:'static_pages#contact'


  # 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

它向我显示了一个错误

syntax error, unexpected tIDENTIFIER, expecting keyword_end
match '/contact' to:'static_pages#contact'
                   ^
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245:in `block in load'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245:in `load'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:40:in `each'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:40:in `load_paths'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:16:in `reload!'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:26:in `block in updater'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/file_update_checker.rb:78:in `call'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/file_update_checker.rb:78:in `execute'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:27:in `updater'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/finisher.rb:66:in `block in <module:Finisher>'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/initializable.rb:30:in `instance_exec'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/initializable.rb:30:in `run'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/initializable.rb:54:in `each'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/initializable.rb:54:in `run_initializers'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application.rb:136:in `initialize!'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /home/ritesh/projects/sample_app/config/environment.rb:5:in `<top (required)>'
    from /home/ritesh/projects/sample_app/spec/spec_helper.rb:3:in `require'
    from /home/ritesh/projects/sample_app/spec/spec_helper.rb:3:in `<top (required)>'
    from /home/ritesh/projects/sample_app/spec/requests/static_pages_spec.rb:1:in `require'
    from /home/ritesh/projects/sample_app/spec/requests/static_pages_spec.rb:1:in `<top (required)>'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `block in load_spec_files'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `map'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load_spec_files'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.9.0/lib/rspec/core/command_line.rb:22:in `run'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:69:in `run'
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:10:in `block in autorun'

为什么会出现这个语法错误我认为这个代码行是正确的书面匹配'/contact'到:'static_pages#contact'请帮助纠正它。

4

1 回答 1

2

你之前忘记了逗号to:

match '/help', to:'static_pages#help'
match '/about', to:'static_pages#about'
match '/contact', to:'static_pages#contact'
于 2012-12-18T21:55:23.383 回答