Rake Aborted语法错误Ruby

时间:2014-11-06 15:23:15

标签: ruby-on-rails ruby ruby-on-rails-3 rake

我已经开始使用http://guides.rubyonrails.org/getting_started.html学习Ruby on Rails了。我对编程并不陌生,但Ruby on Rails与我以前的不同。

我在第5步,我需要创建一个新的文章资源。当我修改config / routes.rb文件时,如下所示:

Blog2::Application.routes.draw do
get "welcome/index"

Blog2::Application.routes.draw do

resources :posts 


# 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
#   

# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
#root :to => 'articles#new'


 root :to => 'welcome#index'

end 

我在rake路线上一直出错,并说:

rake aborted!
SyntaxError: C:/rubygems/blog2/config/routes.rb:68: syntax error, unexpected $en
d, expecting keyword_end
C:in execute_if_updated' C:/rubygems/blog2/config/environment.rb:5:in'
Tasks: TOP => routes => environment
(See full trace by running task with --trace)

我知道它的第68行并且与#34;结束"但我确保"结束"没有注释。

有谁知道这是什么问题?

1 个答案:

答案 0 :(得分:5)

每次启动块时,您都会调用方法Blog2::Application.routes.draw两次。虽然你只关闭其中一个块。解决方案是删除routes.rb文件的第4行(Blog2::Application.routes.draw do)。