私は予約モデル、コントローラ、ビューを持っています。ユーザーは予約を行うことができ、ドライバーは後で予約を請求することができます。予約の作成は正常に動作していますが、未請求の予約をすべてドライバに表示することができますが、ドライバがクレームボタンに当たったときにドライバIDで予約を更新することはできません。私は予約モデルに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
ドライバコントローラ
クラス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)ドライバビュー
<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
レーキルート
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
あなたのルートを共有することができます... 2番目のパラメータは通過する方法ではありません...しかし、私はあなたにルートを見た後に正しいパスを与えることができます... – SnehaT
ありがとうSnehaT、私はルートを追加しました。 – Mayank