Shopify/shopify_api — Issue #14: theme_id not stored in prefix options from Asset.find
Author: dylanahsmith
Created: 2011-12-09 23:00:16+00:00
State: open

When Asset.find is called with theme_id in the params, then the theme_id is used for the path_prefix, but not stored in the resulting objects prefix_options. As a result, saves will occur on the published rather than unpublished theme returned by the find method.

```ruby
asset = ShopifyAPI::Asset.find 'templates/index.liquid', params => { :theme_id => unpublished_theme.id }
asset.prefix_options # => {}
asset.value # => "old value"
asset.value = "new value"
asset.save # => true
asset = ShopifyAPI::Asset.find 'templates/index.liquid', params => { :theme_id => unpublished_theme.id }
asset.value # => "old value"
```

The reason this is happening, is that ActiveResource::Base doesn't use split_options(options[:params]) to instantiate_record with the prefix options in find_one, even though it does this for find_single:

```ruby
# Find a single resource from a one-off URL
def find_one(options)
case from = options[:from]
when Symbol
instantiate_record(get(from, options[:params]))
when String
path = "#{from}#{query_string(options[:params])}"
instantiate_record(connection.get(path, headers))
end
end

# Find a single resource from the default URL
def find_single(scope, options)
prefix_options, query_options = split_options(options[:params])
path = element_path(scope, prefix_options, query_options)
instantiate_record(connection.get(path, headers), prefix_options)
end
```

So the find request will look like this:
`GET "/admin/themes/4/assets.json?asset%5Bkey%5D=templates%2Findex.liquid&theme_id=4"`
where theme_id became a query parameter, rather then being stored in the returned object.