我制作了一个简单的应用程序,让用户可以跟踪他们的销售线索。除了注销用户的主页外,一切正常,他们收到错误消息 - nil:NilClass 的未定义方法“leads”。
线索控制器中的索引:
def index
@leads = current_user.leads.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @leads }
end
end
主页:
<% if user_signed_in? %>
<div class="row">
<div class="span3">
<h2>Leads</h2>
</div>
<div class="pull-right">
<%= link_to 'Add New Lead', new_lead_path, class: 'btn btn-primary' %>
</div>
</div>
<div>
<table id="leads" class="display">
<thead>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Phone</th>
<th class="hidden-tablet hidden-phone hidden-desktop-small">Website</th>
<th class="hidden-tablet hidden-phone hidden-desktop-small">Email</th>
<th class="hidden-tablet hidden-phone hidden-desktop-small">Notes</th>
<th class="hidden-tablet hidden-phone hidden-desktop-small">Last Updated</th>
</tr>
</thead>
<tbody>
<% @leads.each do |lead| %>
<tr>
<td><%= link_to lead.company_name, lead %></td>
<td><%= lead.contact %></td>
<td><%= lead.phone %></td>
<td class="hidden-tablet hidden-phone hidden-desktop-small"><%= lead.website %></td>
<td class="hidden-tablet hidden-phone hidden-desktop-small"><%= lead.email %></td>
<td class="hidden-tablet hidden-phone hidden-desktop-small"><%= lead.notes %></td>
<td class="hidden-tablet hidden-phone hidden-desktop-small"><%= lead.updated_at.strftime("%d %b %y") %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
<% else %>
<div class="hero-unit">
<h1>Welcome to SnapLeads</h1>
<p>
The simplest CRM ever.
</p>
<p>
<%= link_to "Sign up now!", new_user_registration_path, class: "btn btn-primary btn-large" %>
</p>
</div>
<% end %>
如果用户已注销,为什么页面会尝试访问潜在客户方法?