【发布时间】: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