2013-06-19 21 views
0

我在Rails應用程序中使用Rails和Devise。當使用Firefox但不使用Chrome時current_user可用

在我的代碼中,我試圖在layouts/_header.html.erb中使用current_user。

<% Rails.logger.debug("Time is: #{Time.now} - Current User: #{current_user}") %> 

當我使用Firefox我的Mac上運行的應用程序,這是我在日誌文件中:

Time is: 2013-06-18 16:21:42 - Current User: #<User:0x007fae442cf020> 

當我使用Chrome我的Mac上運行的應用程序,這是我在日誌文件中有:

Time is: 2013-06-18 16:20:33 - Current User: 
Rendered layouts/_promo_bar.html.erb (3.4ms) 
Completed 500 Internal Server Error in 657ms 

ActionView::Template::Error (undefined method `email' for nil:NilClass): 
    27: <div class="promo-bar-box last-right-box"> 
    28:  <div class="request-invitation-text"> 
    29:  <% Rails.logger.debug("Time is: #{Time.now} - Current User: #{current_user}") %> 
    30:  <% reg_user = user_registered_for_event(current_user.email) %> 

app/views/layouts/_promo_bar.html.erb:30:in `_app_views_layouts__promo_bar_html_erb__785786602602486184_70193263335300' 

任何想法?

+1

你真的使用Chrome登錄到應用程序嗎? current_user將是零,直到你做 - 使用'user_signed_in?'來檢查 – house9

回答

1

看起來您正在訪問的頁面尚未登錄。如果會話未設置,則current_user將不會存在,並在嘗試訪問其某個屬性時發生錯誤,在這種情況下是用戶的電子郵件。

如果您已經登錄,請嘗試通過Devloper工具(漢堡包圖標>工具>開發者工具)清除會話cookie。並重新加載頁面。

+0

我有一些代碼來檢查用戶是否登錄,然後使用current_user。我意外刪除了它,沒有注意到。你的回答給了我需要解決問題的提示,並且我能夠從我的GitHub倉庫中獲得以前的版本。 – EastsideDeveloper

相關問題