Skip to content

rociiu/sql_query

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SqlQuery

It’s a simple plugin that for search within model fields

Install Plugin

Install plugin from github

./script/plugin install git@github.com:rociiu/sql_query.git

Example

Without option:

#Post(title:string, content:text)
class Post
	
  include SqlQuery
  sql_query #with no options, it will search in all string or text base field

end

With Option:

#Post(title:string, content:text)
class Post
	
  include SqlQuery
  sql_query :fields => [:title, :content]

end

Search:

Post.sql_search('hello') # it will generate sql 'SELECT * FROM "posts" WHERE ( title like '%hello%' or content like '%hello%') '

Under the method sql_search is named_scope, so you can use it with will_paginate

Post.sql_search('hello').paginate(:page => 1, :per_page => 15)

Example goes here.

Copyright © 2009 [rociiu0112@gmail.com], released under the MIT license

About

a simple rails plugin for sql query

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published