我正试图在我的导航中的按钮中显示当前用户名称, 如果它们被签名的话。 我将不使用 Home 控制器来做任何操作, 为什么它要定义名称? 任何涉及其它控制器的页面在试图在导航中创建用户时都会出错 。 @ info: whatsthis
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>