如果他们已登录,我试图在我的导航中的按钮中显示当前用户的名称。我不使用 Home 控制器做任何事情,为什么要求在其中定义名称?尝试在导航中呈现 user.name 时,任何涉及不同控制器的页面都会出错。
NoMethodError in Home#index
Showing /Users/nelsonkeating/Desktop/ReminDeal/app/views/layouts/_navigation.html.erb where line #10 raised:
undefined method `name' for nil:NilClass
Extracted source (around line #10):
7: <% if user_signed_in? %>
8: <div class="logout1">
9: <div class="btn-group">
10: <button class="btn"><Action> <%= @user.name %> </button>
11: <button class="btn dropdown-toggle" data-toggle="dropdown">
12: <span class="caret"></span>
13: </button>
<ul class="dropdown-menu">
<li><%= link_to 'Logout', destroy_user_session_path, :method=>'delete' %></li>
<li><%= link_to 'My Account', edit_user_path(current_user.id) %></li>
<li><%= link_to "Help", help_path %></li>
</ul>
</div>
</div>
</li>