app/views/reports/_form.html.erb
<%= form_for(report, html: { class: 'simple-form report' } ) do |f| %>
<% if report.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(report.errors.count, "error") %> prohibited this report from being saved:</h2>
<ul>
<% report.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :title %><br>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :slug %>
<span class="slug-suggestion"
data-url="<%= slug_suggestion_url title: '-title-', format: :json %>">
suggestion: <span class="suggestion"></span>
<a href="#use">use</a>
</span>
<br>
<%= f.text_field :slug %>
</div>
<div class="field">
<%= f.label :body %><br>
<%= f.text_area :body %>
</div>
<div class="field">
<%= f.label :category %><br>
<%= f.collection_select :category_id, categories, :id, :name, prompt: '-- Select --' %>
</div>
<ul class="report-pictures media-list">
<%= f.fields_for :pictures do |picture_field| %>
<%= render 'picture_item', f: picture_field, html_class: 'section' %>
<% end %>
<%= f.fields_for :pictures, Picture.new, child_index: '--replace--' do |picture_template| %>
<%= render 'picture_item', f: picture_template, html_class: 'template' %>
<% end %>
</ul>
<% if report.pictures.size < Report::MAX_PICTURES %>
<%= button_tag 'Add Picture', type: 'button', class: 'add-picture',
data: {
'replace-pattern' => '--replace--',
'max-items' => Report::MAX_PICTURES
}
%>
<% end %>
<div class="clear"></div>
<div class="actions">
<%= f.submit class: 'submit' %>
</div>
<% end %>