Rails 3.0, want to match 'UK' == 'United Kingdom' in ActiveRecord model -
I have a problem, I have a country model where DB entry is: {: name = & gt; 'United Kingdom'}
I have data UK instead of United Kingdom . In other models where I have searched for it:
But I have to do all this and the application Just bad.
So the question: How can I do a search in the country model, which only searches for. When it does a query, I do not want {: name = & gt; 'Uk'} .
e.g. If I search for UK and should exclude the result {: name = & gt; 'United Kingdom'} not {: name = & gt; 'Uk'} .
The solution is okay if I can just put a few stupid hacks:
name = "United Kingdom" if searchstring == "UK you have your country The model can add a customer finder method:
class country & lt; ActiveRecord :: base def self.by_name (name) name == 'UK'? Search_by_name ('United Kingdom'): find_by_name (name) end end then you country.by_name ('...') whenever you need to find the country by your name Alternatively, if you select find_by_name the terms of the law:
class country There are several variations, if name == 'UK' where (: Name = & gt; name) end
ActiveRecord :: base df self.find_by_name (name) name = 'United Kingdom' around this I think I am in favor of another example Because it presents the same API as a dynamic feature-based searcher, which is called ActiveRecord ie. find_by_XXX etc.
Comments
Post a Comment