更新后,当我尝试启动我的 ruby 应用程序时,出现错误:
undefined method `[]' for nil:NilClass
提取的源代码(第 8 行附近):
8: <% account = Account.find_mak -%>
app/models/account.rb:68:in `find_mak'
app/views/layouts/_js_api_init.html.erb:8:in `block in _app_views_layouts__js_api_init_html_erb___274999121_65047152'
app/views/layouts/_js_api_init.html.erb:1:in `_app_views_layouts__js_api_init_html_erb___274999121_65047152'
app/views/layouts/logged_out.html.erb:17:in `_app_views_layouts_logged_out_html_erb__713588534_51277824'
app/controllers/leads_controller.rb:11:in `new'
config/initializers/newrelic_instrumentation.rb:30:in `call'
config/initializers/newrelic_instrumentation.rb:51:in `call'
但是,我不明白第 8 行发生了什么,我该如何调试这个错误?如果您需要更多信息来回答,请写评论。谢谢。
class Account
include Mongoid::Document
include Mongoid::Timestamps
attr_accessible :org_name, :time_zone
field :org_name
... ...
def self.find_mak
where( org_name: 'Mak' ).first
end
end
现在在其他地方出错
<%= form_tag "/apps/#{Account.find_mak.api_key}/users",
method: :post, remote: true,
'data-type' => 'json',
id: 'register',
:class => 'custom register' do %>