0

誰かが私を正しい方向に向けることができるのだろうか. 私はサービスとサービス予約モデルを持っています。私の servicebooking テーブルには、id、service_name、service_id、date、time、および user_id というフィールドがあります。サービス ビュー ページに「サービスの予約」リンクがあり、予約を保存するときに、現在のサービス名と ID を servicebookings テーブルと現在のユーザー ID に保存したいと考えています。

以下は、私のサービス コントローラの作成アクションですが、どうすればよいかわかりません。隠しフィールドなどを介して、サービス ID と名前のパラメータにアクセスする必要があることはわかっています。ご協力いただきありがとうございます。

サービスには多くのサービス予約があり、ユーザーには多くのサービスとサービス予約があります。Service と servicebooking はユーザーに属します。

def create
    @servicebooking = current_user.servicebookings.build(params[:servicebooking].permit(:service_id, :date, :time, :user_id))
    @servicebooking = //Need some help here

    if @servicebooking.save
      redirect_to @servicebooking
    else
      render 'new'
    end
  end

//////EDIT - マイ サービスの表示ビュー

<h2><%= @service.name %></h2><%= link_to 'Book this service', new_servicebooking_path %>

<p>
  <strong>Name:</strong>
  <%= @service.name %>
</p>

<p>
  <strong>Date Available:</strong>
  <%= @service.date_available %>
</p>

<p>
  <strong>Time Available:</strong>
  <%= @service.time_available %>
</p>

//////EDIT2 My Services 編集ビュー

<%= form_for @servicebooking, :html => {  :multipart => true } do |f| %>
  <% if @servicebooking.errors.any? %>
  <div id="errorExplanation">
    <h2><%= pluralize(@servicebooking.errors.count, "error") %> prohibited
      this service booking from being saved:</h2>
    <ul>
    <% @servicebooking.errors.full_messages.each do |msg| %>
      <li><%= msg %></li>
    <% end %>
    </ul>
  </div>
  <% end %>



  <p>
    <%= f.label :date %><br>
    <%= f.text_area :date %>
  </p>

  <p>
    <%= f.label :time %><br>
    <%= f.text_area :time %>
  </p>

  <p>
    <%= f.submit %>
  </p>
<% end %>
4

1 に答える 1