Skip to content

Instantly share code, notes, and snippets.

@abitdodgy
Created November 21, 2016 19:28
Show Gist options
  • Save abitdodgy/35082ca7bb49fcc33cfd0a7a67afac7a to your computer and use it in GitHub Desktop.
Save abitdodgy/35082ca7bb49fcc33cfd0a7a67afac7a to your computer and use it in GitHub Desktop.
Medium Article: Medium Article: Building Many-to-Many Associations with cast_assoc and Nested Forms in Phoenix and Ecto
<%= form_for @changeset, registration_path(@conn, :create), fn f -> %>
<div class="form-group">
<%= label f, :name %>
<%= text_input f, :name, class: "form-control" %>
<%= error_tag f, :name %>
</div>
<div class="form-group">
<%= inputs_for f, :memberships, fn mf -> %>
<%= inputs_for mf, :user, fn uf -> %>
<div class="form-group">
<%= label uf, :email %>
<%= text_input uf, :email, class: "form-control" %>
<%= error_tag uf, :email %>
</div>
<% end %>
<% end %>
</div>
<%= submit "Create", class: "btn btn-primary" %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment