index.html.erb中的NameError

时间:2014-06-20 02:52:38

标签: ruby-on-rails view nameerror

我遇到问题让我的布局在localhost:3000 /技能渲染。这是我的观看代码:

这是index.html.erb视图:

<% 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>

这是我的错误:

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>

它指向的具体行是:

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

我认为c.id是我数据库的无效参数,但我不确定。我将继续努力解决它并感谢任何知道任何事情的人。干杯,祝你好运!

1 个答案:

答案 0 :(得分:3)

<% 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>

你必须移动&lt;%end%&gt;在你结束使用它之后。我想它是在最后一次

之后
<% 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 %>