【发布时间】:2012-06-24 07:47:16
【问题描述】:
routes.rb
resources :home do
get 'download', :on => :collection
end
rake 路线
download_home_index GET /home/download(.:format) home#download
home_index GET /home(.:format) home#index
....
home_controller.rb
def index
end
当我访问 http://localhost:3000/home/download 时,即使 home_controller 中没有“下载”操作,它也能正常工作。我很困惑为什么即使没有动作,它也不会抱怨缺少动作。
我很好奇,所以我在 routes.rb 中添加了resources :homes,rake routes 给了我以下信息:
homes GET /homes(.:format) homes#index
相比之下,它不是homes_index,而之前是home_index。是否有一些轨道魔术正在发生?欣赏一些解释。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 rails-routing