title: render a new comment form at the end of post#show
body: <p>For a basic blog application (<code>Post</code> <code>has_many</code> <code>comments</code>) I want to display a new comment form at the end of <code>post#show</code>. But I'm stuck with the mechanics of building it and rendering the <code>web/templates/comment/form.html.eex</code> in <code>web/templates/user/show.html.eex</code>. The application:</p>
  
  <pre><code>mix phoenix.new my_app
  cd my_app
  mix ecto.create
  mix phoenix.gen.html Post posts content:string
  mix phoenix.gen.html Comment comments content:string \
  post_id:references:posts
  mix ecto.migrate
  </code></pre>
  
  <p><strong>web/models/post.ex</strong></p>
  
  <pre class="lang-elixir prettyprint-override"><code>defmodule MyApp.Post do
    use MyApp.Web, :model
  
    schema "posts" do
      field :content, :string
      has_many :comments, MyApp.Comment
  
      timestamps
    end
  
    @required_fields ~w(content)
    @optional_fields ~w()
  
    def changeset(model, params \\ :empty) do
      model
      |&gt; cast(params, @required_fields, @optional_fields)
    end
  end
  </code></pre>
  
  <p><strong>web/models/comment.ex</strong></p>
  
  <pre class="lang-elixir prettyprint-override"><code>defmodule MyApp.Comment do
    use MyApp.Web, :model
  
    schema "comments" do
      field :content, :string
      belongs_to :post, MyApp.Post
  
      timestamps
    end
  
    @required_fields ~w(content post_id)
    @optional_fields ~w()
  
    def changeset(model, params \\ :empty) do
      model
      |&gt; cast(params, @required_fields, @optional_fields)
    end
  end
  </code></pre>
  
  <p>In the <code>Post</code> controller I have the first problem. This code doesn't work (<code>key :post not found in: %{}</code> error):</p>
  
  <p><strong>web/controllers/post_controller.ex</strong></p>
  
  <pre class="lang-elixir prettyprint-override"><code>[...]
  def show(conn, %{"id" =&gt; id}) do
    post = Repo.get!(Post, id)
  
    changeset =
      conn.assigns.post
      |&gt; build_assoc(:comments)
      |&gt; Comment.changeset()
  
    render(conn, "show.html", post: post, changeset: changeset)
  end
  [...]
  </code></pre>
  
  <p>The next problem is that I have no idea how to render the form. The following code doesn't work:</p>
  
  <p><strong>web/templates/post/show.html.eex</strong></p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;h2&gt;Show post&lt;/h2&gt;
  
  &lt;ul&gt;
    &lt;li&gt;
      &lt;strong&gt;Content:&lt;/strong&gt;
      &lt;%= @post.content %&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
  
  &lt;%= render "comment/form.html", changeset: @changeset,
                          action: comment_path(@conn, :create) %&gt;
  </code></pre>
  
  <p>How can I fix this?</p>