title: Saving current service name and id to a servicebooking model
body: <p>I wonder if someone could point me in the right direction. I have service and servicebooking models. My servicebooking table has fields: id, service_name, service_id, date, time and user_id. I have a 'book service' link on my service view page and when saving the booking I want to save the current service name and id to the servicebookings table and the current user id.</p>
  
  <p>Below is my service controllers create action, but I'm not sure how to go about this, I know I need to access the service id and name parameters maybe through hidden fields etc, can any help here? Thanks for your help.</p>
  
  <p>Service has many servicebooking and users have many service and servicebooking.
  Service and servicebooking belong to user.</p>
  
  <pre><code>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
  </code></pre>
  
  <p>//////EDIT - My Services show view</p>
  
  <pre><code>&lt;h2&gt;&lt;%= @service.name %&gt;&lt;/h2&gt;&lt;%= link_to 'Book this service', new_servicebooking_path %&gt;
  
  &lt;p&gt;
    &lt;strong&gt;Name:&lt;/strong&gt;
    &lt;%= @service.name %&gt;
  &lt;/p&gt;
  
  &lt;p&gt;
    &lt;strong&gt;Date Available:&lt;/strong&gt;
    &lt;%= @service.date_available %&gt;
  &lt;/p&gt;
  
  &lt;p&gt;
    &lt;strong&gt;Time Available:&lt;/strong&gt;
    &lt;%= @service.time_available %&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>//////EDIT2 My Services edit view</p>
  
  <pre><code>&lt;%= form_for @servicebooking, :html =&gt; {  :multipart =&gt; true } do |f| %&gt;
    &lt;% if @servicebooking.errors.any? %&gt;
    &lt;div id="errorExplanation"&gt;
      &lt;h2&gt;&lt;%= pluralize(@servicebooking.errors.count, "error") %&gt; prohibited
        this service booking from being saved:&lt;/h2&gt;
      &lt;ul&gt;
      &lt;% @servicebooking.errors.full_messages.each do |msg| %&gt;
        &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt;
      &lt;% end %&gt;
      &lt;/ul&gt;
    &lt;/div&gt;
    &lt;% end %&gt;
  
  
  
    &lt;p&gt;
      &lt;%= f.label :date %&gt;&lt;br&gt;
      &lt;%= f.text_area :date %&gt;
    &lt;/p&gt;
  
    &lt;p&gt;
      &lt;%= f.label :time %&gt;&lt;br&gt;
      &lt;%= f.text_area :time %&gt;
    &lt;/p&gt;
  
    &lt;p&gt;
      &lt;%= f.submit %&gt;
    &lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>