Created
November 10, 2008 08:15
-
-
Save augustl/23447 to your computer and use it in GitHub Desktop.
Experimental finder syntax thingie, lol.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| require 'active_support' | |
| # Turns | |
| # c('title LIKE ', "%#{query}%", ' AND published = ', true) | |
| # into | |
| # ['title LIKE ? AND published = ?', "%#{query}%", true] | |
| # | |
| # In other words, ladies and mentlegen, you can now do a find as such: | |
| # find(:all, :conditions => c('gender =', params[:gender], 'AND published =', true)) | |
| # | |
| # I don't think I'll ever, ever use this myself. | |
| def c(*conditions) | |
| conditions.in_groups_of(2).inject([""]) do |ary, group| | |
| ary[0] << "#{group[0].strip} ? " | |
| ary << group[1] | |
| ary | |
| end | |
| end | |
| query = "hey" | |
| puts c('title LIKE', "%#{query}%", 'AND published =', true).inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment