views:

17

answers:

1

I am trying to port an existing rails app running rails 2.3.8 to 3.0.0beta4.

I currently use this paginate_by_sql hack

module ActiveRecord 
    class Base 
        def self.find_by_sql_with_limit(sql, offset, limit) 
            sql = sanitize_sql(sql) 
            add_limit!(sql, {:limit => limit, :offset => offset}) 
            find_by_sql(sql) 
        end 
        def self.count_by_sql_wrapping_select_query(sql) 
            sql = sanitize_sql(sql) 
            count_by_sql("select count(*) from (#{sql}) as x") 
        end 
   end 
end 

The add_limit! method has been removed from ActiveRecord::Base class. Are there any work arounds for this? Any alternatives to doing pagination by SQL in Rails 3.0.0?

Thanks

A: 

hmm, fwiw, this seems to work.

module ActiveRecord 
    class Base 
        def self.find_by_sql_with_limit(sql, offset, limit) 
            sql = sanitize_sql(sql) 
            find_by_sql(sql + " LIMIT #{offset},#{limit}") 
        end 
        def self.count_by_sql_wrapping_select_query(sql) 
            sql = sanitize_sql(sql) 
            count_by_sql("select count(*) from (#{sql}) as x") 
        end 
   end 
end 
Anand S