Deprecation Warning on Save with Ruby and Active_Record

DEPRECATION WARNING on save with ruby and active_record

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

Rails 5: DEPRECATION WARNING: You are passing an instance of ActiveRecord::Base to `exists?`. ..I have no idea

Contact Exists (0.4ms) SELECT 1 AS one FROM "contacts" WHERE "contacts"."id" = $1 LIMIT $2 [["id", 166574], ["LIMIT", 1]]

This is telling you that your contact already exists so if you want that code to work then create a contact that does not already exist or change your models code that does this check or the database schema if that is where you have a unique property set, you have NO error in your code, the warning is just a deprecation warning not an error.
You seem to be accessing a record that already exists so maybe you are wanting to update rather than create? this may be a logic error rather than a coding error but only you know what it is you are trying to do

Rails 5 Deprecation Warning The behavior of `attribute_change`

I changed the method's body to

saved_changes.empty? || (saved_changes.keys & %w(first_name last_name title organization_name)).present?

and it seems to be working the same but without the million deprecation warnings.

It seems the same goes for changed? which now prefers to be called saved_changes?

Deprecation warnings on Rails 3 RC don't help me

Have you got full logging turned on? If so - check your log-files for a full backtrace. The full backtrace should point out the full calling-stack including the line of your code that caused the issue.

Rails 5.1.1 deprecation warning changed_attributes

Well, got around everything by running bundle update and updating the gems and also following this article and changing attribute_changed? calls in after_ callbacks (but not in before_ callbacks and validations) and switching from attribute_was to attribute_before_last_save.

Using changed and changed_attributes in validation before saving gives a depreciation warning

I figured things out thanks to this earlier answer:
https://stackoverflow.com/a/44987787/4983172

class Post < ApplicationRecord
validate :cannot_change_after_publishing, on: :update

def cannot_change_after_publishing
return if published_at_change_to_be_saved && published_at_in_database.nil?

unchangeable = %w[message author other_things]
errors.add(:published_at, "Oh dang!") if unchangeable.any? {|attr| changed_attribute_names_to_save.include?(attr)
end
end

Again though, if anyone sees a better way, feel free to throw it in.



Related Topics



Leave a reply



Submit