【发布时间】:2016-08-05 05:13:36
【问题描述】:
我缺少联系人#show 前缀“联系人”,如下所示。
搜索路线
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"):
我遇到的每篇文章都用点而不是斜线似乎源于复数错误,但是,我不相信这里是这种情况。
此外,我已经从我的路由文件中删除了资源 :contacts,运行 $ rake 路由,添加了资源 :contacts,运行 $ rake 路由,问题仍然存在。
这个问题似乎是联系人模型独有的,因为我的其余模型在删除时没有丢失任何前缀或出现此错误。
如何将“联系人”前缀添加回“联系人#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
【问题讨论】:
-
试试
<%= link_to "delete contact", contact_path(contact), method: :delete, data: { confirm: "You sure?" } %> -
同样的路由错误,很遗憾。
标签: ruby-on-rails ruby routes