开发者

No implicit conversion from float to nil - Rails 3

I get this error:

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

Around this line:

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

Which is in this block:

<% @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 %>

This is my Plan model:

# == 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)
#

Thoughts ?

Edit1: Unfortunately, I am getting this error in production, not on my dev machine, so the stack trace is very limited. I also can't replicate it locally. The entire message I am getting from Heroku is:

2011-04-18T19:45:52+00:00 ap开发者_C百科p[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: Updated my plan schema above, and including my User schema below:

# == 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
#


I think it's more likely that time_ago_in_words(user.last_sign_in_at) is causing the error because user.last_sign_in_at is nil.

The log message is giving you more context, but the line in the middle is the one causing the error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜