Rails-settings: NoMethodError: undefined `merge 'method for []: array

I am trying to embed gim-rails-settings (https://github.com/100hz/rails-settings) in a Rails 3 project using Ruby 1.8.7

Setting and retrieving settings works fine, but I get an error message if I try to get all the settings for a specific user.

So, in the "rails" console, the following actions are performed:

user = User.find(123)
user.settings.color = :red
user.settings.color

But if I try to get all the settings:

user.settings.all

I get:

NoMethodError: undefined `merge 'method for []: Array

from /โ–บ....BIZ/. rvm / gems / ruby-1.8.7-p334 / bundler / gems / rails-settings-883114dfd933 / lib / rails-settings / settings.rb: 55: in `all '

from (irb): 5

line 55 in settings.rb:

#retrieve all settings as a hash (optionally starting with a given namespace)
def self.all(starting_with=nil)
  options = starting_with ? { :conditions => "var LIKE '#{starting_with}%'"} : {}
  vars = thing_scoped.find(:all, {:select => 'var, value'}.merge(options))

  result = {}
  vars.each do |record|
    result[record.var] = record.value
  end
  # line 55 is below this one...
  @@defaults.select{ |k| k =~ /^#{starting_with}/ }.merge(result).with_indifferent_access
end

What is the problem? Or is it ruby โ€‹โ€‹1.8.7 versus 1.9.2?

+3
source share
2

Ruby 1.8.7 1.9.2

Hash ruby โ€‹โ€‹1.8.7 .

:

{:a => 'a', :b => 'b', :c => 'c'}.select {|k, v| v > 'a'} #=> [[:b,'b'],[:c,'c']]

Ruby 1.9.2:

{:a => 'a', :b => 'b', :c => 'c'}.select {|k, v| v > 'a'} #=> {:b => 'b',:c => 'c'}

hsah - inject.

Edit:

/ inject

{:a => 'a', :b => 'b', :c => 'c'}.inject({}) {|r, e| e[1] > 'a' ? r.merge({e[0] => e[1]}) : r }

:

collection.inject(container) { |container, element| select_condition ? container + element : container }

2: ( @CaleyWoods)

Hash[*@@defaults.select{ |k,v| k =~ /^#{starting_with}/ }.flatten].merge(result)

|k, v| .

+3

, Array Ruby. Merge Hash, , . , "with_indifferent_access" , .

, . , .

, vars. , . , , , .

0

All Articles