【发布时间】:2015-01-17 23:57:32
【问题描述】:
大家好,我正在尝试熟悉 Rails,我在 Windows 7 上使用 aptana studio 3 创建了一个说控制器。当我转到 'localhost:3000/say/hello' 时,它给了我一个路由错误,没有指定路由, ETC.. 所以我在网上查看并找到了几种解决方案,我尝试一一应用它们,但我的路线说现在似乎没有任何效果
Rails.application.routes.draw do
get 'say/hello'
get 'say/goodbye'
#map.connect 'say/hello', :controller => 'say', :action => 'hello'
#map.connect ':controller/:action/:id'
#map.connect ':controller/:action/:id.:format'
#match ':controller(/:action(/:id))(.:format)'
#link_to "hello", :controller => "mycontroller", :action => "myaction"
match '/say/hello' => 'Say#hello', :as => 'say_hello'
#root :to => 'Say#hello'
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
# root 'welcome#index'
# Example of regular route:
# get 'products/:id' => 'catalog#view'
# Example of named route that can be invoked with purchase_url(id: product.id)
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
# Example resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Example resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Example resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Example resource route with more complex sub-resources:
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', on: :collection
# end
# end
# Example resource route with concerns:
# concern :toggleable do
# post 'toggle'
# end
# resources :posts, concerns: :toggleable
# resources :photos, concerns: :toggleable
# Example resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
end
当我转到演示目录并手动转到 routes.rb 文件时,我注意到一件事,除了我输入的 match 命令的注释内容之外什么都没有。这会是它不起作用的原因吗?我保存在 aptana 中不应该反映这一点吗?
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3