stoft
stoft

Reputation: 1275

KeyError in Phoenix web framework

I get the following error in the client when trying to serve a page to the client:

(KeyError) key :id not found in: %Phtest.Jobs{"@class": "Job", "@rid": "#13:0", "@type": "d", "@version": 1, description: "öoisajdf sadöflkjasdfö lkj", job_status: "Open", job_type: "Developer", title: "Foo"} Stacktrace

(phtest) web/templates/page/index.html.eex:27: Phtest.PageView."-index.html/1-lc$^0/1-0-"/1
(phtest) web/templates/page/index.html.eex:16: Phtest.PageView."index.html"/1
...

It was working earlier but now I've modified my model somewhat switching out job.id for job."@rid". My template looks like this:

<ul class="list-unstyled" style="">
  <%= for job <- @jobs do %>
  <li class="job-list">
    <div class="row">
      <div class="col-md-9">
        <a href="/jobs/<%= job."@rid" %>">
          <span class="title"><%= job.title %></span>
          <span class="label label-success"><%= job.job_type %></span>
          <span class="label label-default"><%= job.job_status %></span>
        </a>
      </div>
      <div class="col-md-3 buttons" style="text-align: right">
        <!-- <form method="post" action="<%= job_path(:destroy, job.id) %>"> -->
        <a href="/jobs/<%= job."@rid" %>/edit" class="btn btn-warning btn-sm">
          Edit</a> &nbsp;&nbsp;
          <a href="/jobs/<%= job."@rid" %>?action=delete" class="btn btn-default btn-sm">
            Delete</a>
<!--          <input type="hidden" name="_method" value="DELETE">
          <button type="submit" class="btn btn-default btn-sm">Delete</button>
        -->
      </div>
    </div>
  </li>
  <% end %>
</ul>

Upvotes: 3

Views: 1310

Answers (1)

stoft
stoft

Reputation: 1275

The first line of the stack trace shows where the error is in the template.

The template in turn is still referring to the old job.id which is still being evaluated despite being within HTML comment brackets. Either correct it to job."@rid", remove the code entirely or comment out the EEx template code like this:

<!-- <form method="post" action="<%= #job_path(:destroy, job.id) %>"> -->

Upvotes: 3

Related Questions