Skip to content

Fix deprecation: pass id instead of object to .exists?#219

Merged
tom93 merged 1 commit intomasterfrom
deprecation-exists-id
Dec 30, 2023
Merged

Fix deprecation: pass id instead of object to .exists?#219
tom93 merged 1 commit intomasterfrom
deprecation-exists-id

Conversation

@tom93
Copy link
Contributor

@tom93 tom93 commented Dec 23, 2023

Fixes some deprecation warnings from Rails 4.2 update (#199).

Not fully tested (only checked that the tests pass).

From the commit message:

Fixes the following Rails 4.2 deprecation warning:

DEPRECATION WARNING: You are passing an instance of ActiveRecord::Base to exists?. Please pass the id of the object by calling .id.

See: https://guides.rubyonrails.org/4_2_release_notes.html#active-record-deprecations

Fixes the following Rails 4.2 deprecation warning:

    DEPRECATION WARNING: You are passing an instance of ActiveRecord::Base to `exists?`. Please pass the id of the object by calling `.id`.

See: https://guides.rubyonrails.org/4_2_release_notes.html#active-record-deprecations
@tom93 tom93 mentioned this pull request Dec 23, 2023
tom93 added a commit that referenced this pull request Dec 28, 2023
Steps:
* Update Gemfile
* bundle update --conservative rails actionpack railties activerecord activemodel activesupport rack responders

Also add an explicit dependency on responders, because Rails 4.2 moved
the `respond_with` method out to a separate gem[1]. (We're currently
okay because devise depends on responders, but seeing how we're
explicitly using the `respond_with` method we should add an explicit
dependency.)

There are lots of warnings & deprecations, but nothing is _failing_ in
the test suite. The deprecation warnings will be fixed separately
(e.g. #219, #220).

Note that due to a change in Rack, `rails server` now listens on
`localhost` instead of `0.0.0.0` by default in development mode[2][3].
This prevents connections from other machines for security. The older
behaviour can be achieved using `rails server -b 0.0.0.0`. (Also, when
using `rails server` without `-b`, note that `localhost` may resolve
to an IPv6 address depending on the operating system, in which case
http://127.0.0.1:3000 won't work; instead, use http://localhost:3000.)

[1] https://guides.rubyonrails.org/4_2_release_notes.html#respond-with-class-level-respond-to
[2] https://guides.rubyonrails.org/4_2_release_notes.html#default-host-for-rails-server
[3] rack/rack@28b0144

Co-authored-by: Tom Levy <tomlevy93@gmail.com>
@tom93 tom93 merged commit 3a9b1d8 into master Dec 30, 2023
@tom93 tom93 deleted the deprecation-exists-id branch December 30, 2023 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants