secret
Last active

  • Download Gist
Acts_as_indexed and UTF-8.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
# sudo gem install stringex
# "Щукинская".to_ascii => Shchukinskaia
# "щукинская".to_ascii => shchukinskaia
 
require 'stringex'
class Post < ActiveRecord::Base
acts_as_indexed :fields => [:ascii_title, :ascii_body]
 
private
def ascii_title
self.title.to_ascii
end
def ascii_body
self.body.to_ascii
end
end
 
class PostsController < ApplicationController
 
def search
@posts = Post.find_with_index(params[:query].to_ascii)
end
 
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.