我收到此错误:
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)
#
想法?
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
#
答案 0 :(得分:1)
我认为time_ago_in_words(user.last_sign_in_at)
更有可能导致错误,因为user.last_sign_in_at
是nil
。
日志消息为您提供了更多上下文,但中间的行是导致错误的行。