我得到这个错误:
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 %>
这是我的Plan模型:
# == 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)
#
想法吗?
Edit1:不幸的是,我在生产中得到这个错误,而不是在我的开发机器上,所以堆栈跟踪非常有限。我也不能在本地复制它。我从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
#
我认为time_ago_in_words(user.last_sign_in_at)
更有可能导致错误,因为user.last_sign_in_at
是nil
。
日志信息给你更多的上下文,但中间的行是导致错误的。