#4 ✓resolved
Maciej Litwiniuk

order_by_link throws error - nonexisting method deep_merge!

Reported by Maciej Litwiniuk | September 24th, 2008 @ 08:31 AM

Under Rails 2.1.0 searchgasm throws an error, that HashWithIndifferentAccess does not have method deep_merge!

Here's patch: --- a/vendor/plugins/searchgasm/lib/searchgasm/helpers/utilities.rb +++ b/vendor/plugins/searchgasm/lib/searchgasm/helpers/utilities.rb @@ -106,4 +106,26 @@ module Searchgasm end end

+class Hash + def deep_merge!(second) + second.each_pair do |k,v| + if self[k].is_a?(Hash) and second[k].is_a?(Hash) + self[k].deep_merge!(second[k]) + else + self[k] = second[k] + end + end + end +end + +class HashWithIndifferentAccess < Hash + def initialize(constructor = {}) + if constructor.is_a?(Hash) + super() + update(constructor) + else + super(constructor) + end + end +end ActionController::Base.helper(Searchgasm::Helpers::Utilities) if defined?(ActionController)

Comments and changes to this ticket

  • Maciej Litwiniuk

    Maciej Litwiniuk September 24th, 2008 @ 08:32 AM

    patch once again

    
    diff --git a/vendor/plugins/searchgasm/lib/searchgasm/helpers/utilities.rb b/vendor/plugins/searchgasm/lib/searchgasm/helpers/utilities.rb
    index 4cf0497..dd02676 100644
    --- a/vendor/plugins/searchgasm/lib/searchgasm/helpers/utilities.rb
    +++ b/vendor/plugins/searchgasm/lib/searchgasm/helpers/utilities.rb
    @@ -106,4 +106,26 @@ module Searchgasm
       end
     end
    
    +class Hash
    +  def deep_merge!(second)
    +    second.each_pair do |k,v|
    +      if self[k].is_a?(Hash) and second[k].is_a?(Hash)
    +        self[k].deep_merge!(second[k])
    +      else
    +        self[k] = second[k]
    +      end
    +    end
    +  end
    +end
    +
    +class HashWithIndifferentAccess < Hash
    +  def initialize(constructor = {})
    +    if constructor.is_a?(Hash)
    +      super()
    +      update(constructor)
    +    else
    +      super(constructor)
    +    end
    +  end
    +end
     ActionController::Base.helper(Searchgasm::Helpers::Utilities) if defined?(ActionController)
    
  • Ben Johnson

    Ben Johnson October 15th, 2008 @ 02:00 PM

    • State changed from “new” to “resolved”
  • Ben Johnson

    Ben Johnson October 28th, 2008 @ 02:05 AM

    • Assigned user set to “Ben Johnson”
  • Pak24tv

    Pak24tv December 9th, 2020 @ 01:05 AM

    I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post. top 10 richest countries in the world top 10 poorest countries in the world top 10 most beautiful places in the world

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Provides common named scopes and object based searching.

People watching this ticket

Pages