Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Admin side product search not functioning #1570

wants to merge 1 commit into from

4 participants


1) Make a new order from the orders tab in the admin
2) Attempt to search for a SKU
3) Witness it not function


I can verify this issue and I know the fix for it, however there's another problem after that. I get undefined method serializable_hash for ActiveRecord::Relation when it attempts to include the variants association on the JSON that it is returning. That's a little frustrating.

I don't know how to fix that particular error right now, but will look into it again later on.


I've turned this issue into a pull request with the fix. If you're game, you can try out the commit in a local copy of Spree and see if you can fix the issue.


I started trying to fix this issue as well before I figured out how to search to see if it was already reported. My research has led me to the conclusion that the serializable_hash error can be removed by changing

        collection.to_json(:include => {:variants => {:include => {:option_values => {:include => :option_type}, 
                                                      :images => {:only => [:id], :methods => :mini_url}}}, 
                                                      :images => {:only => [:id], :methods => :mini_url}, :master => {}})


        collection.to_json(:include => {:variants => {:include => {:option_values => {:include => :option_type}, 
                                                      :images => {:only => [:id], :methods => :mini_url}}}, 
                                                      :master => {}})

I was able to write a controller test that causes this error. If you are interested, I can send along a pull request.

I'll try out your patch locally and let you know if it resolves the problem for me.


With your patch, I'm not getting the error, but I'm also not getting any results.


This appears to have been introduced by 4b48e3f. Product#variant_images used to return an array of Image, but now it returns an ActiveRecord::Relation.

Adding .all to the end of the AREL expression fixes the undefined method serializable_hash for ActiveRecord::Relation issue, but it seems to result in a bunch of other test failures.

Any advice?


This is starting to look like a Rails issue. Instances of ActiveRecord::Relation are not passing the is_a?(Enumberable) test on But ActiveRecord::Relation will correctly return a valid value for { |a| a.serializable_hash(opts) }.


@mscottford yes, it's possibly a Rails issue.
This is because there are no more association images for Products, while :include option takes only enumerables (association target array is enumerable) and not scopes, which are AR::Relation.

In this case I see two ways.
1. :methods => :images instead of :include => :images
2. Why images is a method and not an association?

    has_many :images, :through => :variants_including_master,
                      :order => "#{Asset.quoted_table_name}.position",
                      :readonly => true

It's much cleaner than find_by_sql, i feel.


Thanks @alekseydem. Adding :methods => images instead of :include => :images does prevent the crash, and results do come back. However, each image in the json response is not in the format expected by the Javascript. It expects the image to look like


but it is coming across as


It does not look like Object#to_json supports providing options to the :methods that get called.


I've figured out how to solve this. I'll send a pull request in a few minutes.


Pull request sent. radar#3

@radar radar closed this in ac2c1ac
@joahking joahking referenced this pull request from a commit in joahking/spree
@mscottford mscottford Adds a `serializable_hash` method to the result of `Product#variant_i…

Fixes #1570
@tvdeyen tvdeyen referenced this pull request from a commit in magiclabs/spree
@mscottford mscottford Adds a `serializable_hash` method to the result of `Product#variant_i…

Fixes #1570
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 22, 2012
  1. @radar
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  core/app/assets/javascripts/admin/admin.js.erb
2  core/app/assets/javascripts/admin/admin.js.erb
@@ -121,7 +121,7 @@ $.fn.product_autocomplete = function(){
return this.each(function() {
source: function(request, response) {
- $.get(ajax_root_prefix() + "admin/products.json?q=" + $('#add_product_name').val() + "&authenticity_token=" + encodeURIComponent($('meta[name=csrf-token]').attr("content")), function(data) {
+ $.get(ajax_root_prefix() + "admin/products.json?q[name_cont]=" + $('#add_product_name').val() + "&authenticity_token=" + encodeURIComponent($('meta[name=csrf-token]').attr("content")), function(data) {
result = prep_product_autocomplete_data(data)
Something went wrong with that request. Please try again.