rails/rails — Issue #3917: ActiveResource attributes removed if they're in prefix_options
Author: jessegoodnoe
Created: 2011-12-09 17:04:01+00:00
State: open

A similar bug was posted in [lighthouse](https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2230) but was marked stale and I can't find an equivalent here on github. So I'm creating a new one.

If an ActiveResource has attributes that are also used on the URL (i.e. in the prefix params) they will not be in the object's attributes, but will instead be in the prefix_options. They should also be in the attributes.

# Example

In this example, the Chapter object retrieved from the remote REST API has a book_id on it.

```ruby
class chapter < ActiveResource::Base
self.prefix = "/book/:book_id/"
end

chapter = Chapter.find(:first, :params => { :book_id => 123 })
chapter.book_id
```

The call to `chapter.book_id` will return undefined method book_id.

If you inspect the chapter, the book_id is in the prefix_options, but not the attributes. Since the book_id comes back in the response from the REST API, I'd expect it to be in both the prefix_options and the attributes.