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

Don't use ActiveModel#has_attribute? due to Rails 4 bug #144

Merged
merged 1 commit into from
Aug 20, 2015

Conversation

ozydingo
Copy link
Contributor

The end result is a confusing error: "ActiveModel::MissingAttributeError: missing attribute: state" due to the following bug in Rails 4:

Job.select("id").first.attribute_names
=> ["state", "id"]

In Rails 5:

Job.select("id").first.attribute_names
=> ["id"]

If code loops through model.attribute_names to display selected values, the error results:

job = Job.select("id").first; job.attribute_names.map{|n| job[n]}
ActiveModel::MissingAttributeError: missing attribute: state

With the current pull request:

job = Job.select("id").first; job.attribute_names.map{|n| job[n]}
=> [1]

The bug can be traced to a bug in Rails 4's has_attribute? method which adds the attribute name to the list even if it was not selected. To support this, since this is the current stable version, we can use attribute_names.include? instead of has_attribute?

@troessner
Copy link
Owner

Awesome - merged!

I'll release a new version of transitions later today.

Thanks a lot for this contribution!

troessner pushed a commit that referenced this pull request Aug 20, 2015
Don't use ActiveModel#has_attribute? due to Rails 4 bug
@troessner troessner merged commit 42a19f3 into troessner:master Aug 20, 2015
@troessner
Copy link
Owner

And 0.2.1 is released.:)

@ozydingo
Copy link
Contributor Author

Sweet, thanks! That fixed the issue!

On Thu, Aug 20, 2015 at 5:51 AM, Timo Rößner notifications@github.com
wrote:

And 0.2.1 is released.:)


Reply to this email directly or view it on GitHub
#144 (comment)
.

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.

2 participants