gpt4 book ai didi

ruby-on-rails - Rails - 缺少路由助手前缀

转载 作者:太空宇宙 更新时间:2023-11-03 16:44:38 25 4
gpt4 key购买 nike

我缺少 contacts#show 前缀“contact”,如下所示。

rake 路

               contacts GET    /contacts(.:format)                     contacts#index
POST /contacts(.:format) contacts#create
new_contact GET /contacts/new(.:format) contacts#new
edit_contact GET /contacts/:id/edit(.:format) contacts#edit
GET /contacts/:id(.:format) contacts#show
PATCH /contacts/:id(.:format) contacts#update
PUT /contacts/:id(.:format) contacts#update
DELETE /contacts/:id(.:format) contacts#destroy

我想这就是为什么我在单击以下链接时得到的是点而不是斜线的原因。

_contact.html.erb

<%= link_to "delete contact", contact, method: :delete,
data: { confirm: "You sure?" } %>

服务器记录正确的 DELETE 请求,但是无法呈现/contact.26 而不是正确的/contacts/26。

Started DELETE "/contact.26" for 128.177.12.30 at 2016-04-13 21:04:30 +0000

ActionController::RoutingError (No route matches [DELETE] "/contact.26"):

我遇到的每一篇用点而不是斜杠的帖子似乎都源于复数错误,但是,我不认为这里是这种情况。

此外,我已经从我的路由文件中删除了 resources :contacts,运行 $ rake routes,添加了 resources :contacts,运行 $ rake routes,问题仍然存在。

这个问题似乎是联系人模型独有的,因为我的其他模型在删除时没有丢失任何前缀或出现此错误。

如何将“联系人”前缀添加回“联系人#show”?

routes.rb 文件供引用:

Rails.application.routes.draw do
root 'static_pages#home'
get 'help' => 'static_pages#help'
get 'about' => 'static_pages#about'
get 'contact' => 'static_pages#contact'
get 'signup' => 'users#new'
get 'login' => 'sessions#new'
get 'newevent' => 'events#new'
get 'newteam' => 'teams#new'
get 'newperformance' => 'performances#new'
get 'newhotel' => 'hotels#new'
get 'newcontact' => 'contacts#new'
get 'newflight' => 'flights#new'
get 'newground' => 'grounds#new'
get 'newguest' => 'guests#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'
resources :users
resources :events
resources :teams do
member do
get :events
end
end
resources :performances
resources :hotels
resources :contacts
resources :flights
resources :grounds
resources :guests
resources :account_activations, only: [:edit]
resources :password_resets, only: [:new, :create, :edit, :update]
end

最佳答案

你设置的路由之间可能有冲突

 resources :contacts

get 'contact' => 'static_pages#contact'

最简单的解决方案可能是更改静态页面的链接。如果可以,最好将资源放在一起。

关于ruby-on-rails - Rails - 缺少路由助手前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36609727/

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