0

I am using Rails and Devise in a Rails application.

In my code, I am trying to use current_user in layouts/_header.html.erb.

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

When I use Firefox on my MAC to run the application, here's what I have in the log file:

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

When I use Chrome on my MAC to run the application, here's what I have in the log file:

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'

Any ideas?

4

1 回答 1

1

看起来您正在访问一个页面而尚未登录。如果未设置会话,则 current_user 将不存在,并在尝试访问其属性之一时抛出错误,在本例中是用户的电子邮件。

如果您已登录,请尝试通过开发者工具(汉堡图标 > 工具 > 开发者工具)清除会话 cookie。并重新加载页面。

于 2013-06-19T00:29:05.040 回答