Skip to content

Instantly share code, notes, and snippets.

@gregnowicki
Created May 12, 2014 00:45
Show Gist options
  • Save gregnowicki/5fbe99e814330c1b371c to your computer and use it in GitHub Desktop.
Save gregnowicki/5fbe99e814330c1b371c to your computer and use it in GitHub Desktop.
cocoon form builder
# _form.html.erb is the primary form
<%= simple_form_for(@contact) do |f| %>
<% if @contact.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@contact.errors.count, "error") %> prohibited this contact from being saved:</h2>
<ul>
<% @contact.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.input :name %>
<%= f.input :title %>
<%= f.input :company %>
<%= f.input :email %>
<%= f.input :notes %>
<h3>Goals:</h3>
<%= f.simple_fields_for(:goals) do |goal| %>
<%= render 'goal_fields', :f => goal %>
<%= link_to_add_association 'add goal', f, :goals %>
<%= f.submit :submit %>
<% end %>
<% end %>
# _goal_fields.html.erb is the Goal fields being rendered in the above form
<%= f.input :title %>
<%= f.input :due_date %>
<%= f.input :notes %>
<%= link_to_remove_association "remove goal", f %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment