gpt4 book ai didi

ruby-on-rails - rails 4 : You should not use the `match` method in your router without specifying an HTTP method

转载 作者:行者123 更新时间:2023-12-04 00:19:26 25 4
gpt4 key购买 nike

好的,所以我已经升级到 Rails 4(在我的 10.9 服务器更新中是计划外的)并且能够在我的照片库应用程序上运行除路线之外的所有内容。出于某种原因,自从 rails 3 以来,我一直无法理解路线。这是我之前在 Rails 3 下的工作代码

root :to => "gallery#index", :as => "gallery"

get 'gallery' => 'gallery#index'
resources :galleries

match 'gallery_:id' => 'gallery#show', :as => 'gallery'

我知道 match 已折旧,但如果我尝试使用 GET,则会收到以下错误:

Invalid route name, already in use: 'gallery' 您可能已经使用 :as 定义了两条同名的路由。选项,或者您可能会覆盖已由具有相同命名的资源定义的路由。

基本上,我希望根(索引)像它一样加载为“/photos/gallery”,并且我的显示 Action 要加载,例如,将 id 435 记录为:“/photos/gallery_435”,这是我以前的方式工作。抱歉,这可能是一个简单的问题,我似乎无法掌握 Rails 路由。

最佳答案

试试这个

match 'gallery_:id' => 'gallery#show', :via => [:get], :as => 'gallery_show'

然后,您可以在帮助程序和 View 中将此路径称为 gallery_show_path。

更改“as”会消除冲突。

关于ruby-on-rails - rails 4 : You should not use the `match` method in your router without specifying an HTTP method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19798466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com