Skip to content

Update 2.0.0 appears to break for POROsΒ #81

@cjhutchi

Description

@cjhutchi

I recently updated to the latest version (2.0.0), and in our app we use this gem on some POROs. Here's an example of how we use it:

class PatientForm
  include ActiveModel::Model
  include ActiveModel::Attributes
  include ActiveModel::Validations::Callbacks

  strip_attributes only: :last_name, collapse_spaces: true

  ...
end

After the update, the callback to collapse_spaces seemed to break with this error:

undefined method '[]=' for an instance of PatientForm

I was able to fix it by manually just defining the [] and []= methods on the model

class PatientForm
  include ActiveModel::Model
  include ActiveModel::Attributes
  include ActiveModel::Validations::Callbacks

  strip_attributes only: :last_name, collapse_spaces: true

  def [](key)
    send(key)
  end

  def []=(key, value)
    send("#{key}=", value)
  end
  ...
end

Is this an actual bug in the release, or are the callbacks not intended to be used with objects that don't get persisted to the database like this and we should use the gem directly instead?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions