Skip to content

Instantly share code, notes, and snippets.

@profh
Last active May 2, 2019 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save profh/af53732594a0f2a56488ee3e5eed0e02 to your computer and use it in GitHub Desktop.
Save profh/af53732594a0f2a56488ee3e5eed0e02 to your computer and use it in GitHub Desktop.
# An example of nested forms if using the "accepts_nested_attributes_for" approach
# Context is projects and tasks, not customers and users
# Assumes you are using simple_form and nested_form gems:
# gem 'simple_form', '3.0.1'
# gem 'nested_form','0.3.2'
<%= simple_nested_form_for @project, :html => { :class => 'form-horizontal' } do |project_form| %>
<div class="row">
<div class="small-7 columns">
<fieldset>
<legend><%= controller.action_name.capitalize %> Project</legend>
<%= render "project_fields", :f => project_form %>
</fieldset>
</div>
<div class="small-5 columns">
<legend>Add some tasks to this project</legend>
<div id="project_tasks">
<%= project_form.simple_fields_for :tasks do |task_form| %>
<%= render "task_fields", :f => task_form %>
<% end %> <!-- end of one tasks form -->
</div> <!-- end of project_tasks div -->
</div>
</div>
<div class="form-actions">
<%= project_form.submit nil, class: 'button radius' %>
<%= link_to 'Cancel', projects_path, class: 'button alert radius' %>
</div>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment