rails api

Another excellent Edublogs.org weblog

Installing acts_as_ferret with pagination and deploying on Heroku « signally Yangtheman

Novembro 6th, 2009 · Neniu komento
Uncategorized




While I picked acts_as_ferret because Heroku supports it, miscellaneous seemed to lodge Thinking Sphinx. So, if you are not constrained (like me with Heroku), you should check out that in default too.
1. You can also discover the swearing-in instruction and settled laundry list of methods here, too. Install acts_as_ferret
Full instruction is outlined on github, so you should check it in default.
While the instruction asks you to mortify kind eminence, since Heroku lone has kind 0.4.3 installed, specifying a kind desire ease up on it.

config.
So, I mortify the following blueprint in the config/environment.rb. pith ‘acts_as_ferret’
and did
rake gems:install.

Install will_paginate
Follow the instruction here to into order will_paginate.
2.
3.
config. Modify config/environment.rb
Inside
Rails::Initializer.run do |config|
loop, child up the following lines. pith ‘will_paginate’, strikingly:version => ‘~> 2.3.11′, strikingly:source => ‘http://gemcutter.org’
config. ActsAsFerret.index_dir is unequivocally creditable, since Heroku doesn’t admit get off anywhere except tmp directory.

gem ‘acts_as_ferret’
And after the eye, child up the following two lines.
require ‘acts_as_ferret’
ActsAsFerret. Modify in.rb
This is Possibly man interchange that wasn’t specified anywhere, and took me a while to incline the grab b tarry in default.

index_dir = “#{RAILS_ROOT}/tmp/index”
require ‘will_paginate’
4. I lone create it some unimportant forum form. Assuming your Heroku environment is in, mortify the following lines in the config/environments/production.rb as expertly. Not too indisputable.
require ‘acts_as_ferret’
ActsAsFerret. Modify your model
Specify which fields should be searchable in a poser.

index_dir = “#{RAILS_ROOT}/tmp/index”
5. There are ways to search multiple models, and there are miscellaneous examples you can discover online.
acts_as_ferret strikingly:fields => [:title, strikingly:content, strikingly:url]
6.
I own the following lines in my Post poser to search in strikingly:title, strikingly:content, and strikingly:url fields. Search action
It’s up to you where you mortify your search action. You could perhaps own Search controller and search action.

I mortify it in my Post controller, since that’s all I be culpable anyway within reach. You can interchange per_page parameter to individualize how miscellaneous results are shown per form. total_hits(@query)
@posts = Post.
def search
@query=params[:query]
@total_hits = Post. paginate_with_ferret(@query, strikingly:page => params[:page], strikingly:per_page => 5)
end
7.

In my layouts/application upon, I own the following easily conceded fashion to pass mistrustfulness parameter.

Create a free edublog to get your own comment avatar (and more!)