I currently have these 3 search methods in my rails model, they are all
the same apart from which field they search (take a look at the 5th line
inside each method).

def self.search(*args)
  return [] if args.blank?
  cond_text, cond_values = [], []
  args.each do |str|
  next if str.blank?
  cond_text << "( %s )" % str.split.map{|w| "game_name LIKE ? "}.join("
OR ")
  cond_values.concat(str.split.map{|w| "%#{w}%"})
end
all :conditions =>  [cond_text.join(" AND "), *cond_values]
end

def self.gensearch(*args)
  return [] if args.blank?
  cond_text, cond_values = [], []
  args.each do |str|
  next if str.blank?
  cond_text << "( %s )" % str.split.map{|w| "genre LIKE ? "}.join(" OR
")
  cond_values.concat(str.split.map{|w| "%#{w}%"})
end
all :conditions =>  [cond_text.join(" AND "), *cond_values]
end

def self.consearch(*args)
  return [] if args.blank?
  cond_text, cond_values = [], []
  args.each do |str|
  next if str.blank?
  cond_text << "( %s )" % str.split.map{|w| "console LIKE ? "}.join(" OR
")
  cond_values.concat(str.split.map{|w| "%#{w}%"})
end
all :conditions =>  [cond_text.join(" AND "), *cond_values]
end



I currently have the following in my controller:

   @games = Game.search(params[:search])
   @games = Game.gensearch(params[:search])
   @games = Game.consearch(params[:search])




and the following in my view:

   <%= form_tag games_path, :controller => 'games', :action => 'search',
:method => 'get' do %>
        <%= text_field_tag :search, params[:search] %>
        <%= submit_tag t('.searchb'), :game_name => nil %>
   <% end %>

   <%= form_tag games_path, :controller => 'games', :action =>
'gensearch', :method => 'get' do %>
        <%= text_field_tag :search, params[:search] %>
        <%= submit_tag t('.searchb'), :game_name => nil %>
   <% end %>

   <%= form_tag games_path, :controller => 'games', :action =>
'consearch', :method => 'get' do %>
        <%= text_field_tag :search, params[:search] %>
        <%= submit_tag t('.searchb'), :game_name => nil %>
   <% end %>


I am having a problem that no matter what form I type text in to, it
searches all the forms and displays the text in each form as if they are
all connected. It will only return results that match all three columns
as well despite me stating what action I want each to link_to.

Any ideas on what I should change?

Thanks.

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to