语法错误,意外的tIDENTIFIER,期待keyword_end

时间:2012-12-18 21:51:16

标签: ruby-on-rails ruby-on-rails-3.2 railstutorial.org

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'     请帮助纠正它。

1 个答案:

答案 0 :(得分:2)

您在to:

之前忘记了逗号
match '/help', to:'static_pages#help'
match '/about', to:'static_pages#about'
match '/contact', to:'static_pages#contact'