Skip to content

Commit

Permalink
Fixed sqlite compat in page model
Browse files Browse the repository at this point in the history
  • Loading branch information
jbbarth committed Feb 1, 2009
1 parent c9b1806 commit 2f69919
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/models/page.rb
Expand Up @@ -64,20 +64,20 @@ def before_update


# get a page based on permalink # get a page based on permalink
def self.find_by_link(permalink) def self.find_by_link(permalink)
self.find(:first, :conditions => ['is_active = 1 and permalink = ?', permalink]) self.find(:first, :conditions => ['is_active = ? and permalink = ?', true, permalink])
end end


# find all pages in the db that contain string # find all pages in the db that contain string
def self.find_by_string(str, limit = 20, active_only = false) def self.find_by_string(str, limit = 20, active_only = false)
# use the search lib to run this search # use the search lib to run this search
results = self.search(str, {:conditions => (active_only ? 'is_active = 1' : nil), :limit => limit}) results = self.search(str, {:conditions => (active_only ? ['is_active = ?', true] : nil), :limit => limit})
if (results.length > 1) or (str.downcase.index(' and ')) if (results.length > 1) or (str.downcase.index(' and '))
# if the first search returned something or there was an AND operator # if the first search returned something or there was an AND operator
return results return results
else else
# first search didn't find anthing, let's try it with the OR operator # first search didn't find anthing, let's try it with the OR operator
simple_str = str.gsub(' ',' OR ') simple_str = str.gsub(' ',' OR ')
return self.search(simple_str, {:conditions => (active_only ? 'is_active = 1' : nil), :limit => limit}) return self.search(simple_str, {:conditions => (active_only ? ['is_active = ?', true] : nil), :limit => limit})
end end
end end


Expand Down

0 comments on commit 2f69919

Please sign in to comment.