2011-04-18 22 views
0

我得到這個錯誤:從浮到零的隱式轉換 - Rails的3

ActionView::Template::Error (no implicit conversion to float from nil): 

圍繞這一行:

Storage Bought: <%= user.plan.storage %>GB <br /> 

這是此塊:

<% @users.each do |user| %> 
    <br /> 
    <div class="users"> 
    <h3><%= user.username %>/<%= user.plan.name %> ($<%= user.plan.amount %>).</h3> 
    <span class="account-creation">Account created <%= time_ago_in_words(user.created_at) %> ago </span><br /> 

     <div class="col1"> 
      Storage Used: <%= number_to_human_size(user.space_used) %><br /> 
      # of Clients: <%= user.clients.count %><br /> 
      # of Projects: <%= user.projects.count %><br /> 
      # of Stages: <%= user.stages.count %> <br /> 
     </div> 
     <div class="col2"> 
      Storage Bought: <%= user.plan.storage %>GB <br /> 
      # of Uploads: <%= user.uploads.count %> <br /> 
      # of Logins: <%= user.sign_in_count %><br /> 
      Last logged in: <%= time_ago_in_words(user.last_sign_in_at) %> ago. <br /> 
     </div> 
    </div> 
<br /> 
<hr> 
<% end %> 

這是我的計劃模式:

# == Schema Information 
# Schema version: 20110412101615 
# 
# Table name: plans 
# 
# id     :integer   not null, primary key 
# name    :string(255) 
# storage    :float 
# num_of_projects  :integer 
# num_of_clients  :integer 
# cached_slug   :string(255) 
# created_at   :datetime 
# updated_at   :datetime 
# amount    :integer 
# trial_duration  :integer 
# trial_duration_unit :string(255) 
# currency   :string(255) 
# billing_cycle  :integer 
# billing_cycle_unit :string(255) 
# 

想法?

編輯1:不幸的是,我在生產中遇到了這個錯誤,而不是在我的開發機器上,所以堆棧跟蹤非常有限。我也無法在本地複製它。我從Heroku的獲取整個消息是:

2011-04-18T19:45:52+00:00 app[web.1]: Started GET "/stats" for 72.252.30.172 at Mon Apr 18 12:45:52 -0700 2011 
2011-04-18T19:45:52+00:00 app[web.1]: 
2011-04-18T19:45:52+00:00 app[web.1]: ActionView::Template::Error (no implicit conversion to float from nil): 
2011-04-18T19:45:52+00:00 app[web.1]:  44:   Storage Bought: <%= user.plan.storage %>GB <br /> 
2011-04-18T19:45:52+00:00 app[web.1]:  45:   # of Uploads: <%= user.uploads.count %> <br /> 
2011-04-18T19:45:52+00:00 app[web.1]:  46:   # of Logins: <%= user.sign_in_count %><br /> 
2011-04-18T19:45:52+00:00 app[web.1]:  47:   Last logged in: <%= time_ago_in_words(user.last_sign_in_at) %> ago. <br /> 
2011-04-18T19:45:52+00:00 app[web.1]:  48:  </div> 
2011-04-18T19:45:52+00:00 app[web.1]:  49: </div> 
2011-04-18T19:45:52+00:00 app[web.1]:  50: <br /> 
2011-04-18T19:45:52+00:00 heroku[router]: GET myapp.com/stats dyno=web.1 queue=0 wait=0ms service=238ms bytes=965 
2011-04-18T19:45:52+00:00 app[web.1]: app/views/stats/index.html.erb:47:in `_app_views_stats_index_html_erb___1351955738_69932954074060_0' 
2011-04-18T19:45:52+00:00 app[web.1]: app/views/stats/index.html.erb:31:in `each' 
2011-04-18T19:45:52+00:00 app[web.1]: app/views/stats/index.html.erb:31:in `_app_views_stats_index_html_erb___1351955738_69932954074060_0' 

EDIT2:更新上面我的計劃模式,以及包括我下面的用戶模式:

# == Schema Information 
# Schema version: 20110412170916 
# 
# Table name: users 
# 
# id     :integer   not null, primary key 
# email    :string(255) 
# encrypted_password :string(128) 
# password_salt  :string(255) 
# reset_password_token :string(255) 
# remember_token  :string(255) 
# remember_created_at :datetime 
# sign_in_count  :integer 
# current_sign_in_at :datetime 
# last_sign_in_at  :datetime 
# current_sign_in_ip :string(255) 
# last_sign_in_ip  :string(255) 
# username    :string(255) 
# first_name   :string(255) 
# last_name   :string(255) 
# created_at   :datetime 
# updated_at   :datetime 
# invitation_token  :string(60) 
# invitation_sent_at :datetime 
# plan_id    :integer 
# current_state  :string(255) 
# confirmation_token :string(255) 
# confirmed_at   :datetime 
# confirmation_sent_at :datetime 
# space_used   :integer   default(0), not null 
# failed_attempts  :integer   default(0) 
# unlock_token   :string(255) 
# locked_at   :datetime 
# trial_end_date  :date 
# active_subscription :boolean 
# 
+0

'user.plan.storage'的值是什麼? 'user.plan'是否爲非零? – 2011-04-18 19:37:45

+0

這些是他們兩個:'>> admin.plan =>#<計劃ID:8,名稱:「Huey」,存儲:30.0,num_of_projects:99999,num_of_clients:99999,cached_slug:「huey - 2」 ,created_at:「2011-04-18 01:28:54」,updated_at:「2011-04-18 01:28:54」,金額:399,trial_duration:7,trial_duration_unit:「天」,貨幣:無,billing_cycle :無,billing_cycle_unit:無> >> admin.plan.storage => 30.0' 是的,user.plan非零,如上所示。 – marcamillion 2011-04-18 19:39:11

+1

請發佈完整的堆棧跟蹤 – 2011-04-18 19:40:14

回答

1

我認爲這更可能是time_ago_in_words(user.last_sign_in_at)導致錯誤因爲user.last_sign_in_atnil

日誌消息給你更多的上下文,但中間的那一行是導致錯誤的那一行。