Skip to content

Instantly share code, notes, and snippets.

@8parth
Created March 23, 2017 06:35
Show Gist options
  • Save 8parth/c82b787cf48e2bdac6a729d293bf6002 to your computer and use it in GitHub Desktop.
Save 8parth/c82b787cf48e2bdac6a729d293bf6002 to your computer and use it in GitHub Desktop.
# we are saving data to category and subcategory models
<%= form_with(model: @category) do |f| %>
# instead, we can simply pass url, along with scopes if necessary
# <%= form_with(scope: :category, url: category_path) %>
<% if f.object.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(f.object.errors.count, "error") %> prohibited this category from being saved:</h2>
<ul>
<% f.object.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %>
<%= f.text_field :name %>
</div>
<%= f.fields(:sub_categories) do |sub_cat_form| %>
<div class="field">
<%= sub_cat_form.label "sub_category name" %>
<%= sub_cat_form.text_field :name %>
</div>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment