【发布时间】:2019-02-23 02:40:48
【问题描述】:
以前不需要使用 rails 'url helpers',但我正在尝试实现类似 Rails: URL/path with parameters 的东西。我没有创建任何“资源”,但我的印象是我可以在路由中添加 url_helper 名称,例如:
user_index_path GET 'users/index', to: 'users#index'
但这给出了错误:
undefined method 'GET' for #<ActionDispatch::Routing::Mapper:0x00000007ABCDEF> Did you mean? gets gem
由于我没有经常使用它们,我也对我在这里读到的声明感到困惑,https://blog.arkency.com/all-the-ways-to-generate-routing-paths-in-rails/,说“当然,有时你会需要 _url 而不是 _path”。我对它们的定义是错误的吗?是的,我阅读了https://guides.rubyonrails.org/routing.html,并看到了有关“3.16 直接路由”的内容,但这与我“看到”的示例不符。
【问题讨论】:
-
查看guide。如果您尝试将
user_index_path GET 'users/index', to: 'users#index'放入您的routes.rb,那么您就大错特错了。
标签: ruby-on-rails ruby-on-rails-5