Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correctly print errors for active_model_errors for model without a table #42

Merged
merged 2 commits into from
Jun 12, 2020
Merged

correctly print errors for active_model_errors for model without a table #42

merged 2 commits into from
Jun 12, 2020

Conversation

sahglie
Copy link

@sahglie sahglie commented Jun 12, 2020

If you create a ActiveModel class that does not have a table behind it, ap will throw an exception when trying to print the objects errors:

class TableFreeModel
    include ::ActiveModel::Validations
    attr_reader(:name)

    def attributes
      {"name" => name}
    end
end

model = TableFreeModel.new
model.errors.add(:name, "can't be blank")
ap model.errors

#=> NoMethodError (undefined method `column_names' for #<Class:0x00007fe3b6c833f8>)

This pull request fixes this error so that errors are correctly printed regardless of whether the model is back by a table

Fixes #34
Fixes #40

@HarlemSquirrel HarlemSquirrel self-requested a review June 12, 2020 18:09
Copy link
Member

@HarlemSquirrel HarlemSquirrel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply amazing. Fixes two issues in one pull. 🤘

@HarlemSquirrel HarlemSquirrel merged commit 37a55a9 into amazing-print:master Jun 12, 2020
@dmitryzuev
Copy link

Oh, this is magic, I just stumbled upon this error when trying to display model decorated by draper gem, and it was merged into master two hours ago!

Sweet 👍

@manuelmeurer
Copy link

Brilliant, thanks! Could we get a new patch release? 😸

@HarlemSquirrel
Copy link
Member

Done.
https://github.com/amazing-print/amazing_print/releases/tag/v1.2.1

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.

ActiveModel::Errors can't modify frozen String "undefined method 'column_names'" for non-AR classes
4 participants