2012-05-26 3 views
0

로그인 한 경우 내 탐색기의 버튼에 현재 사용자 이름을 표시하려고합니다. 홈 컨트롤러를 사용하지 않습니다. 왜 거기에 이름이 정의되어 있는지 묻습니다. ? 순자산 가치 (NAV)에서 user.name을 렌더링 할 때 다른 컨트롤러가 오류를 줄 관련된 모든 페이지 ..Rails 3.2 : No 메소드 오류

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> 

답변

1

당신이 컨트롤러에서 @user를 선언 한 적이 있습니까? I에 유래이 다른 스레드를 발견

<button class="btn"><Action> <%= current_user.name %> </button>