Changes in _prefix and _suffix in Rails 8
Prior to Rails 8, you could avoid method conflicts using _prefix
and _suffix
. For example:
class Order < ApplicationRecord
enum state: { pending: 0, shipped: 1, delivered: 2 }, _prefix: :order
end
This generated methods like:
order.order_pending? # Instead of order.pending?
order.order_shipped! # Instead of order.shipped!
Rails 8 Change: No Underscore (_) Needed
In Rails 8, you no longer need the _ before prefix
and suffix
:
class Order < ApplicationRecord
enum :state, { pending: 0, shipped: 1, delivered: 2 }, prefix: true
end
This results in the same method generation without requiring an underscore.
order.state_pending? # Rails 8 syntax
This makes prefix/suffix usage cleaner and less error-prone.