У меня есть модель заказа, контроллер, вид. Пользователи могут сделать заказ, и водитель может позже потребовать бронирование. Создание резервной копии работает нормально, я могу отобразить все невостребованные заказы для водителя, однако я не могу обновить бронирование с помощью идентификатора драйвера, когда водитель нажимает кнопку претензии. Я добавил driver_id в модель бронирования и попытался использовать метод обновления в контроллере заказов для обновления поля драйвера, я думаю, что я не передаю параметры правильно link_to. Может кто-то пожалуйста, скажите мне, что я делаю неправильно:Передача неправильных параметров link_to
Бронирование Контроллер:
def update
if @booking.update(booking_params)
redirect_to @booking, notice: "Updated..."
else
render :edit
end
end
private
def set_booking
@booking = Booking.find(params[:id])
end
def booking_params
params.require(:booking).permit(:location_pickup, :location_dropoff, :date_pickup, :date_dropoff, :weight, :load_type)
end
end
контроллер Driver
класс DriversController < ApplicationController before_action: authenticate_driver !, за исключением: [: показать]
def show
@driver = Driver.find(params[:id])
end
def index
@bookings = Booking.where(:driver_id => nil)
end
конец
(драйверы/index.html.erb) Driver Посмотреть
<div class="row">
<div class="col-md-9">
<div class="panel panel-default">
<div class="panel-heading">
Listings
</div>
<div class="panel-body">
<%= current_driver.email %>
<% @bookings.each do |booking| %>
<div class="row">
<div class="col-md-2">
</div>
<div class="col-md-7">
<td> <%= booking.location_pickup %> </td>
<td><%= booking.location_dropoff %></td>
</div>
<div class="col-md-7">
<%= link_to "Claim", update_bookings_path(@booking, driver_id: current_driver.id), :method => :patch, class: "btn btn-primary" %>
</div>
</div>
<% end %>
</div>
</div>
</div>
</div>
routes.rb
Rails.application.routes.draw do
root 'pages#home'
devise_for :users,
:path => '',
:path_names => {:sign_in => 'login', :sign_out => 'logout', :edit => 'profile'},
:controllers => {:registrations => 'registrations'
}
devise_for :drivers,
:path => '/drivers',
:path_names => {:sign_in => 'login', :sign_out => 'logout', :edit => 'profile'},
:controllers => { :registrations => "drivers/registrations" }
resources :users, only: [:show]
resources :drivers, only: [:show, :index, :claim]
resources :bookings
end
Rake маршруты
edit_booking GET /bookings/:id/edit(.:format) bookings#edit
booking GET /bookings/:id(.:format) bookings#show
PATCH /bookings/:id(.:format) bookings#update
PUT /bookings/:id(.:format) bookings#update
DELETE /bookings/:id(.:format) bookings#destroy
Вы можете поделиться своими маршрутами ... Второй параметр - это не способ пройти ... Но я могу дать вам правильный путь только после просмотра маршрутов ... – SnehaT
спасибо SnehaT, я добавил маршруты. Пожалуйста, дайте мне знать, что вы думаете. – Mayank