app/views/lacquers/edit.html.erb
<div class="well">
<legend>Edit <strong><%= link_to @lacquer.name, lacquer_path(@lacquer) %></strong> (<%= @lacquer.brand.name %>)</legend>
<%= form_for @lacquer do |f| %>
<%= f.hidden_field :user_lacquer_id, value: @user_lacquer.id %>
<% if current_user.id == @lacquer.user_added_by_id %>
<%= f.label :name %><br>
<%= f.text_field :name %><br>
<% end %>
<% if current_user.id == @user_lacquer.user_id %>
<%= f.fields_for :user_lacquers, @user_lacquer do |user_lacquer_form| %>
<%= user_lacquer_form.label :colors %><br>
<%= user_lacquer_form.collection_check_boxes :color_ids, Color.all.order(:name), :id, :name do |box| %>
<%= box.label class:"label-checkbox" do %>
<%= box.check_box + box.text %>
<%end%>
<% end %>
<br>
<br>
<%= user_lacquer_form.label :finishes %><br>
<%= user_lacquer_form.collection_check_boxes :finish_ids, Finish.all.order(:description), :id, :description do |box| %>
<%= box.label class:"label-checkbox" do %>
<%= box.check_box + box.text %>
<%end%>
<% end %>
<br>
<h3>Pictures & Swatches for <%= @lacquer.name %></h3>
<div class="menu row">
<% if !@lacquer.picture && !@lacquer.swatches.any? %>
<div class="col-md-12">
<strong>There are no pictures or swatches yet for this lacquer. Upload one to display on your profile page!</strong>
</div>
<% else %>
<div class="col-md-12">
<strong>Select the image you'd like displayed on your profile page (if there's only one image available it will display by default).</strong></div>
<div class="col-md-12 horizontal-scroll small">
<% if @lacquer.picture %>
<div class="thumbnail list-group" style="display: inline-block; float: left; height: 243px; width: 250px; margin-right: 3px;">
<div class="col-md-12" style="padding: 10px;">
<%= user_lacquer_form.radio_button(:selected_display_image, @lacquer.picture) %>
</div>
<%= image_tag @lacquer.picture, style: "height: 170px;" %>
</div>
<% end %>
<% if @lacquer.swatches.any? %>
<% @lacquer.swatches.each do |swatch| %>
<% if swatch.image.file? %>
<div class="thumbnail list-group" style="display: inline-block; height: 243px;">
<div class="col-md-12" style="padding: 10px;">
<%= user_lacquer_form.radio_button(:selected_display_image, swatch.image) %>
</div>
<%= image_tag swatch.image.url, style:"height: 130px;" %><br>
<div class="caption", style="padding-top: 0;">
added by <%= link_to swatch.user.name, user_path(swatch.user) %> on <%= swatch.created_at.strftime("%m/%d/%Y") %><br>
<% if swatch.user == current_user %>
<%= link_to 'delete this swatch', swatch_path(swatch), method: 'DELETE' %>
<% end %>
</div>
</div>
<% end %>
<% end %>
<% end %>
</div>
<% end %>
</div>
<h3>Upload a Swatch for <%= @lacquer.name %></h3>
<%= f.fields_for :swatches, @lacquer.swatches.new, :html => { :multipart => true } do |swatch_form| %>
<p>
<%= swatch_form.hidden_field :user_id, value: current_user.id %>
<%= swatch_form.file_field :image %>
</p>
<% end %>
<h3>Reviews for <%= @lacquer.name %></h3>
<% if @lacquer.reviews.any? %>
<% @lacquer.reviews.each do |review| %>
<p>
Written by <%= link_to review.user.name, user_path(review.user) %> on <%= review.created_at.strftime("%m/%d/%Y at %I:%M%p") %>
<br>
<strong>Rating:</strong> <%= review.rating %>
<br>
<strong>Comments:</strong> <%= review.comments %>
<br>
<% if review.user == current_user %>
<%= link_to 'delete', review_path(review), method: 'DELETE' %> |
<%= link_to 'edit', edit_review_path(review) %>
<% end %>
</p>
<% end %>
<% else %>
No reviews yet!
<% end %>
<% end %>
<% end %>
<h3>Write a Review for <%= @lacquer.name %></h3>
<%= f.fields_for :reviews, @lacquer.reviews.new, class: "form-horizontal" do |review_form| %>
<p>
<%= review_form.hidden_field :user_id, value: current_user.id %>
<div class='form-group'>
<%= review_form.label :rating, "Rating (1 = 'yuck', 5 = 'love it')" %><br>
<%= review_form.number_field :rating, in: 1..5, class: "form-control" %>
</div>
<div class='form-group'>
<%= review_form.label :comments, class: "control-label" %><br>
<%= review_form.text_area :comments, class: "form-control" %>
</div>
</p>
<% end %>
<%= f.submit class: "btn btn-default" %>
<% end %>
</div>