Error
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.

country_code

Convert hash conditions to array conditions (required by find_by_tsearch)
Wednesday, 28 July 2010 16:06
Inspired by http://snippets.dzone.com/posts/show/6839


class Hash
def to_array_conditions
[self.keys.map{|k| "#{k} = ?" }.join(" AND "), self.values].flatten
end
end

test "convert hash conditions to array conditions" do
assert_equal ['city = ? AND country_code = ? AND state = ?',
"Adendorf", "DE", "Niedersachsen"], {
:country_code => "DE",
:state => "Niedersachsen",
:city => "Adendorf"
}.to_array_conditions
end

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/y6Uigqel1FQ/11949

 


Taxonomy by Zaragoza Online