Diamond/pxblog

Part 4: assign @post not available in eex template

Closed this issue · 2 comments

In Part 4 of your blog it says:

web/templates/user/edit.html.eex:
<%= render "form.html", changeset: @changeset, action: user_post_path(@conn, :update, @user, @post), roles: @roles %>

This raises an error:

** (ArgumentError) assign @post not available in eex template.

Guess I missed something. Removing it from the template doen't get me any further. Is the tutorial missing something or did I skip a line?

Just not to add noise to the comment but....man I love your tutorial. Instead of 'another api' tutorial without actual explaining what happens...it's full blown.

I was taking a look and found the issue. I must've copied and pasted the wrong file into that code block; if you look closely you can see that it says "edit post". I copied from web/templates/post/edit.html.eex instead of web/templates/user/edit.html.eex!

Instead, you'll want to replace the code with

<h2>Edit user</h2>
<%= render "form.html", changeset: @changeset,
                        action: user_path(@conn, :update, @user),
                        roles: @roles %>
<%= link "Back", to: user_path(@conn, :index) %>

And that should fix the issue. I've updated the tutorial as well just to make sure that everything is fixed in that regard! Thanks for bringing this to my attention, and thank you for the comment as well! It means a lot to me to hear that people like these posts and I'm always happy to correct any issues that are (constructively) brought to my attention, so thank you!