Releases: AaronLasseigne/active_interaction
Releases · AaronLasseigne/active_interaction
v5.3.0
v5.2.0
Added
- Added translation for Spanish. Thanks @matiasasis!
Fixed
- #545 - Arrays passed in are no longer modified. Thanks @jonkgrimes!
v5.1.1
v5.1.0
v5.0.0
Changed
- Drop support for JRuby.
- Drop support for Ruby 2.5 and 2.6, adding support for 3.1
- Drop support for Rails 5.0 and 5.1
ActiveInteraction::Inputs
no longer inherits fromHash
though it still has most of the methods
provided byHash
(methods that write were removed).- Removed
Filter#clean
(useFilter#process
and call#value
on the result) - The
given?
method has been moved ontoinputs
. (see Upgrade section below) - #503 - The record filter now treats blank strings value as
nil
. This was missed in the 4.0 update. - The
type_check
callback has been renamed tofilter
to better match the reality of what it does.
(see Upgrade section below) ActiveIneraction::FilterColumn
is nowActiveInteraction::Filter::Column
- Errors on the array filter will now be indexed if the Rails config
index_nested_attribute_errors
istrue
or the:index_errors
option is set totrue
. The:index_errors
option always overrides
the Rails config. - Invalid nested errors (
:invalid_nested
) are gone. Instead the nested errors will appear as they would
in Rails if they were ahas_many
relationship being assigned attributes through a parent.
(see Upgrade section below)
Added
Filter#process
which returns anInput
.
Fixed
- When passing an
ActiveRecord::Relation
in an array filter with no inner
filter, the value returned was anActiveRecord::Relation
instead of an
Array.
Upgrading
given?
The given?
method can now be found on inputs
. It works the same as before.
# 4.1
class Example < ActiveInteraction::Base
string :name, default: nil
def execute
given?(:name)
end
end
# 5.0
class Example < ActiveInteraction::Base
string :name, default: nil
def execute
inputs.given?(:name)
end
end
Filter Callback
You'll need to rename any :type_check
callbacks to :filter
.
# 4.1
set_callback :type_check, :before, -> { puts 'before type check' }
# 5.0
set_callback :filter, :before, -> { puts 'before type check' }
Nested Hash Errors
Nested hash errors no longer add an error as through it happened on the hash.
They now use the error in its original form and attach the name of the hash to
the error. It is also not limited to returning one error.
class HashInteraction < ActiveInteraction::Base
hash :mailing_lists do
boolean :marketing
boolean :product_updates
end
def execute
# ...
end
end
> outcome = HashInteraction.run(mailing_lists: {})
# 4.1
> outcome.errors.details
# => {:mailing_lists=>[{:error=>:invalid_nested, :name=>"\"marketing\"", :value=>"nil"}]},
> outcome.errors.messages
# => {:mailing_lists=>["has an invalid nested value (\"marketing\" => nil)"]}
> outcome.errors.full_messages
# => ["Mailing lists has an invalid nested value (\"marketing\" => nil)"]
# 5.0
> outcome.errors.details
# => {:"mailing_lists.marketing"=>[{:error=>:missing}], :"mailing_lists.product_updates"=>[{:error=>:missing}]}
> outcome.errors.messages
# => {:"mailing_lists.marketing"=>["is required"], :"mailing_lists.product_updates"=>["is required"]}
> outcome.errors.full_messages
# => ["Mailing lists marketing is required", "Mailing lists product updates is required"]
I18n can handle these values the same as nested values in Rails:
en:
active_interaction:
attributes:
hash_interaction/mailing_lists:
marketing: 'Mailing list "Marketing"'
product_updates: 'Mailing list "Product Updates"'
Using the same example from above:
> outcome.errors.full_messages
# => ["Mailing list \"Marketing\" is required", "Mailing list \"Product Updates\" is required"]