【问题标题】:Rake Aborted syntax error RubyRake Aborted 语法错误 Ruby
【发布时间】:2014-11-06 15:23:15
【问题描述】:

我已经开始使用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 行,并且与“end”有关,但我确保“end”没有被注释。

有谁知道问题出在哪里?

【问题讨论】:

  • 您的文件中显然不止几行。该块示例在语法上是有效的,但您的实际文件不是。
  • 错误信息表明错误出现在您的config/routes.rb 文件的第 68 行。显示此文件中的所有内容。
  • 检查您的整个routes.rb 文件中是否存在格式不正确的块。第 68 行正是 Ruby 不再能够从语法上理解文件的地方。但错误可能在此之前的任何地方。

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


【解决方案1】:

您调用方法Blog2::Application.routes.draw 两次,每次开始块。尽管您只关闭了这些块中的一个。解决方案是删除 routes.rb 文件 (Blog2::Application.routes.draw do) 的第 4 行。

【讨论】:

  • @Superunknown 我的回答有帮助吗?
  • 行得通!谢谢。我知道我的问题很愚蠢……但我是 Ruby 新手,这与我习惯的概念不同。
猜你喜欢
  • 1970-01-01
  • 2018-07-09
  • 1970-01-01
  • 1970-01-01
  • 2011-04-15
  • 1970-01-01
  • 2017-03-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多