Skip to content

Instantly share code, notes, and snippets.

@stevedomin
Last active March 17, 2016 10:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevedomin/abcdf4a41b00b6e6e981 to your computer and use it in GitHub Desktop.
Save stevedomin/abcdf4a41b00b6e6e981 to your computer and use it in GitHub Desktop.
Phoenix example form
<%= form_for @changeset, @action, fn f -> %>
<div>
<%= label f, :name %>
<%= text_input f, :name %>
</div>
<div>
<%= submit "Submit" %>
</div>
<% end %>
<%= render "form.html", changeset: @changeset,
action: user_path(@conn, :create, @user) %>
defmodule HelloApp.User do
use HelloApp.Web, :controller
def new(conn, _params) do
changeset = HelloApp.User.changeset(%HelloApp.User{})
render(conn, "new.html", changeset: changeset)
end
end
@stevedomin
Copy link
Author

This is a minimal example to show how to create a reusable form template. The create action in the controller has been left out purposefully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment