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

Add more data to AR::UnknownAttributeError #10590

Closed
wants to merge 1 commit into from

Conversation

bogdan
Copy link
Contributor

@bogdan bogdan commented May 13, 2013

This is required in order to be able to rescue such error on app level.

begin
  Topic.new("hello" => "world")
rescue ActiveRecord::UnknownAttributeError => e
  e.record # => #<Topic ... >
  e.attribute # => :hello
end


def initialize(record, attribute)
@record = record
@attribute = attribute.to_sym
Copy link
Member

Choose a reason for hiding this comment

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

Can we do not call to_sym? I think the string is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should convert it to either string or symbol in order to make it deterministic and easy to match against:

if error.attribute == :something
  ...
end

If you think that string is better - I'll change it to to_s

Copy link
Member

Choose a reason for hiding this comment

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

I prefer strings.

Copy link
Member

Choose a reason for hiding this comment

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

👍

begin
  Topic.new("hello" => "world")
rescue ActiveRecord::UnknownAttributeError => e
  e.record # => #<Topic ... >
  e.attribute # => "hello"
end
@tenderlove
Copy link
Member

I merged this, so closing.

@tenderlove tenderlove closed this May 16, 2013
@bogdan bogdan deleted the unknown-attribute-error-data branch May 7, 2014 15:33
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.

None yet

4 participants