我在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'
任何想法?
你真的使用Chrome登錄到應用程序嗎? current_user將是零,直到你做 - 使用'user_signed_in?'來檢查 – house9