launchscout / nku

NKU Class Spring
5 stars 14 forks source link

NameError in #EntriesIndex #18

Closed hopscotchscooter closed 10 years ago

hopscotchscooter commented 10 years ago

So I'm receiving the error below and I'm not quite sure as to why. image

Here's my "index.html.erb" code...

<h1>Student Directory</h1>
<%= link_to 'New Student Entry', new_entry_path %>
<table>
  <tr>
    <th>First Name</th>
    <th>Last Name</th>
    <th>E-mail Address</th>
    <th>Gravatar Image</th>
  </tr>

  <% @entries.each do |e| %>
  <tr>
    <td><%= e.first_name %></td>
    <td><%= e.last_name %></td>
    <td><%= e.email_address %></td>
    <td><%= e.gravatarimage_image_url %></td>
    <td><%= link_to 'Show', @entry %></td>
    <td><%= link_to 'Edit', edit_entry_path(entry) %></td>

  </tr>
  <% end %>
</table>

Also, when I can see all of the entries, the "show" link for each one is just redirecting back to the whole index of entries and I'm not sure why. Here's my rake routes output...

Prefix Verb   URI Pattern                 Controller#Action                                                                                                                                                                   
home_index GET    /home/index(.:format)       home#index                                                                                                                                                                          
   entries GET    /entries(.:format)          entries#index                                                                                                                                                                       
           POST   /entries(.:format)          entries#create                                                                                                                                                                      
 new_entry GET    /entries/new(.:format)      entries#new                                                                                                                                                                         
edit_entry GET    /entries/:id/edit(.:format) entries#edit                                                                                                                                                                        
     entry GET    /entries/:id(.:format)      entries#show                                                                                                                                                                        
           PATCH  /entries/:id(.:format)      entries#update                                                                                                                                                                      
           PUT    /entries/:id(.:format)      entries#update                                                                                                                                                                      
           DELETE /entries/:id(.:format)      entries#destroy                                                                                                                                                                     
      root GET    /                           home#index     

Any help would certainly be appreciated. Thanks in advance.

jaimerump commented 10 years ago

I think you need edit_entry_path(e), since that's the name you used in your for each loop. You're trying to add a link to edit this particular entry out of the list, so you would pass e into the path helper to tell it to generate a link for that particular entry.

hopscotchscooter commented 10 years ago

Thanks a lot @jaimerump . That worked. Can't believe I missed that. That's what I get for being too lazy to type out "entry".