DEPRECATION WARNING on save with ruby and active_record

前端 未结 2 1658
清酒与你
清酒与你 2021-01-24 15:09

I am new to ruby and writing a small script that requires writing messages to a database log.

I am using ruby 1.9.3 with active_record but without rails. All select stat

相关标签:
2条回答
  • 2021-01-24 16:02

    I checked the API and the methods you're using are current. I think you may need attr_accessor

    class ActLog < ActiveRecord::Base
      attr_accessor :id, :level, :message, :module, :date
      self.table_name = "ActLog"
      self.primary_key = "ID"
    end
    
    def log(level, message)
      attr = { :level   => level.upcase!,
               :message => message,
               :module  => 'script',
               :date    => Time.new.strftime("%Y-%m-%d %H:%M:%S") }
      ActLog.new(attr).save!
    end
    
    0 讨论(0)
  • 2021-01-24 16:03

    I think your class should be as follows:

    class ActLog < ActiveRecord::Base
      self.primary_key = 'ID'
      self.table_name = 'ActLog'
    end
    

    Out of curiosity, why the non-standard names?

    0 讨论(0)
提交回复
热议问题