logger.info在Rails模型中不起作用

时间:2019-02-23 01:05:17

标签: ruby-on-rails

Rails 3.2

我过去已成功使用logger.info。今天,我试图调试模型的动作,这破坏了我的应用程序。我的代码(在models / admin_ability.rb中):

can :decline, Ticket do |ticket|
  if ticket.persisted?
    logger.info("File: #{__FILE__ } -- LINE: #{__LINE__ }")
    executor = ticket.executor
    ticket_profile = ticket.ticket_profile
    decliners = ticket.decliners
    suitable_companies = ''
    suitable_companies = ticket_profile.suitable_companies(decliners, ticket.customer, ticket.customer_info.zip, ticket.requested_date_start,
      false, false) if decliners.blank?
    suitable_companies.delete(ticket.executor)
    !(suitable_companies.compact).blank?
  end
end

这是错误消息:

undefined local variable or method `logger' for #<AdminAbility:0x007f8382bfd3f0>
Rails.root: /home/app

Application Trace | Framework Trace | Full Trace
app/models/admin_ability.rb:40:in `block in initialize'

第40行是:

logger.info("File: #{__FILE__ } -- LINE: #{__LINE__ }")

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

logger常量上调用RailsRails.logger.info