Sup*_*own -1 ruby rake ruby-on-rails ruby-on-rails-3
我已经开始使用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
Run Code Online (Sandbox Code Playgroud)
我一直在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)
Run Code Online (Sandbox Code Playgroud)
我知道这是第68行并且与"结束"有关但我确保"结束"没有注释.
有谁知道这是什么问题?
您Blog2::Application.routes.draw
每次启动块时都会调用两次方法.虽然你只关闭其中一个块.解决方案是删除第4行routes.rb
文件(Blog2::Application.routes.draw do
).