ZachyBear
ZachyBear

Reputation: 307

NameError in index.html.erb

I am having an issue getting my layout to render at localhost:3000/skills. Here is my view code:

This is the index.html.erb view:

<% if @skills.blank? %>
<p>There are not any skills currently saved in the system.</p>
<% else %>
<p>These are the current skills saved in our system</p>
<ul id="skills">
<% @skills.each do |c| %>
<li><%= link_to c.title, {:action => 'show', :id => c.id} -%></li>
<% end %>
</ul>
<% end %>
<p><%= link_to "Add new Skill", {:action => 'new' }%></p>


<li>
<%= link_to c.title, {:action => 'show', :id => c.id} -%>
<b> <%= link_to 'Edit', {:action => 'edit', :id => c.id} %></b>
<b> <%= link_to "Delete", {:action => 'delete', :id => c.id},
:confirm => "Are you sure you want to delete this skill??" %></b>
</li>

this is my error:

NameError in Skills#index
 Showing /app/views/skills/index.html.erb where line #16 raised:

undefined local variable or method `c' for #<#<Class:0x000000055b1620>:0x0000000413d338>

and the specific line it is pointing to is:

 <%= link_to c.title, {:action => 'show', :id => c.id} -%>

I think the c.id is an invalid param for my database but I am not sure. I will keep trying to fix it and thanks anyone who knows anything. Cheers and good luck!

Upvotes: 0

Views: 289

Answers (1)

Jorge de los Santos
Jorge de los Santos

Reputation: 4633

<% if @skills.blank? %>
  <p>There are not any skills currently saved in the system.</p>
<% else %>
  <p>These are the current skills saved in our system</p>
  <ul id="skills">
    <% @skills.each do |c| %>
      <li><%= link_to c.title, {:action => 'show', :id => c.id} -%></li>


    <% end %> <- **c ends here**



  </ul>
<% end %>
  <p><%= link_to "Add new Skill", {:action => 'new' }%></p>


<li>
  <%= link_to c.title, {:action => 'show', :id => c.id} -%>
  <b> <%= link_to 'Edit', {:action => 'edit', :id => c.id} %></b>
  <b> <%= link_to "Delete", {:action => 'delete', :id => c.id},
  :confirm => "Are you sure you want to delete this skill??" %></b>
</li>

You have to move <% end %> after you end using it. I suppose it is after the last

<% if @skills.blank? %>
  <p>There are not any skills currently saved in the system.</p>
<% else %>
  <p>These are the current skills saved in our system</p>
  <ul id="skills">
    <% @skills.each do |c| %>
      <li><%= link_to c.title, {:action => 'show', :id => c.id} -%></li>
      <li>
       <%= link_to c.title, {:action => 'show', :id => c.id} -%>
       <b> <%= link_to 'Edit', {:action => 'edit', :id => c.id} %></b>
       <b> <%= link_to "Delete", {:action => 'delete', :id => c.id},
        :confirm => "Are you sure you want to delete this skill??" %></b>
      </li>
    <% end %>
  </ul>
  <p><%= link_to "Add new Skill", {:action => 'new' }%></p>
<% end %>

Upvotes: 3

Related Questions