我有一个servicebooking
模型,当我在accept_booking
展示视图中点击以下链接时,我正在尝试更新其servicebooking
列,其值为:
<%= link_to 'Accept this booking', acceptbooking_servicebooking_path(@servicebooking) %>
我收到以下错误:
undefined method `acceptbooking_servicebooking_path' for #<#<Class:0x5a35e98>:0x5a2bbf0>
下面我在routes.rb
中声明了路线get 'acceptbooking', to: 'servicebookings#acceptbooking'
我的servicebookings控制器中有以下的acceptbooking方法:
def acceptbooking
render nothing: true
@servicebooking = Servicebooking.find(params[:id])
@servicebooking.update_attribute(:accept_booking, 1)
end
我的Routes.rb
Appa::Application.routes.draw do
devise_for :users
devise_for :views
get "welcome/index"
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
root 'welcome#index'
get 'myevents', to: 'events#myevents'
get 'myvenues', to: 'venues#myvenues'
get 'myservices', to: 'services#myservices'
get 'make_available', to: 'services#make_available'
get 'myservicebookings', to: 'servicebookings#myservicebookings'
get 'acceptbooking', to: 'services#acceptbooking'
#match 'acceptbooking', to: 'servicebookings#acceptbooking', via: [:get, :post]
resources :events do
resources :comments
end
resources :users do
resources :events
end
resources :venues do
resources :comments do
collection do
post :venuec
end
end
end
resources :services do
resources :comments do
collection do
post :servicec
end
end
end
resources :servicebookings do
resources :services
end
end
谁能看到我在哪里出错了?谢谢你们。
答案 0 :(得分:1)
试试这个:get 'acceptbooking/:id', to: 'servicebookings#acceptbooking', as: 'acceptbooking_servicebooking'
答案 1 :(得分:0)
仅使用路线定义(来自路线文件):
get 'acceptbooking', to: 'servicebookings#acceptbooking'
路线名称为acceptbooking
,因此您应该使用acceptbooking_path
。但根据您的<%= link_to 'Accept this booking', acceptbooking_servicebooking_path(@servicebooking) %>
,您似乎想要一个类似/servicebookings/:service_booking_id/acceptbooking
的网址。如果是这种情况,那么您应该将路线定义更新为:
resources :servicebookings do
resources :services
# Move the following line here from the top.
get 'acceptbooking', to: 'servicebookings#acceptbooking'
end
这会给你servicebooking_acceptbooking_path
(注意服务预订和接受预订的顺序)。