Reputation: 9184
How can I search first in model (i know how to do this). And then search in this array for more concretence? As you see:
@articles = Article.find(:all, :conditions => { :ART_ID => @search.map(&:ARL_ART_ID)})
@a = @articles.find_all{|item| item.ART_ARTICLE_NR == search.upcase }
First i search in model, but thanks to my db) it have many wrong results, so i must to clarify my array. But there how to search like sql:
like % %
Now it search very strong: if i search AC451, it's good, but if AC45 or C451 it's nothing fetches. How to say him so that before and after
search
could be everything?
Upvotes: 0
Views: 111
Reputation: 26979
You are asking for trouble by not following rails naming conventions an using upper case column names. That said, the rails3 way to do it is probably:
@articles = Article.where(:ART_ID => @search.map(&:ARL_ART_ID)).where('ART_ARTICLE_NR LIKE', "%#{search.upcase}%")
Without knowing what @search is, it's hard to be sure. But you should read up on the active record guide on the rails 3 query format.
Upvotes: 1
Reputation: 419
It's maybe not straigtforward answer, but have you considered using ransack gem?
Upvotes: 0
Reputation: 230336
Like this, maybe?
item.ART_ARTICLE_NR.include?(search.upcase)
Upvotes: 1