railswhere web site:
http://code.google.com/p/railswhere/
rails plugin install URL
http://railswhere.googlecode.com/svn/tags
e.g.
1 common
@companys = Company.find(:all, :conditions => Where{|w|
w.and "companyname like ?", "#%{@companyname}%" if @companyname!=''
w.and "contactman like ?", "#%{@contactman}%" if @contactman!=''
w.and "property = ?", "#{@property}" if @property!=''
w.and "province = ?", "#{@province}" if @province!=''
})
2 paging
@companys = Company.paginate :page => params[:page]|| 1, :per_page => 20,:conditions => Where{|w|
w.and "companyname like ?", "#{@companyname}%" if @companyname!=''
w.and "contactman like ?", "#{@contactman}%" if @contactman!=''
w.and "property = ?", "#{@property}" if @property!=''
w.and "province = ?", "#{@province}" if @province!=''
},:order=>"datetime desc"
very cooooooool!
学了rails才能体会到快乐编程啊
令:直接从主页下载的railswhere在rails2.3.5环境下运行出错。
把railswhere中where.rb中的Clause中的initialize方法中的@criteria = ActiveRecord::Base.send(:sanitize_sql, criteria)改为@criteria = ActiveRecord::Base.send(:sanitize_sql, criteria, nil)即可