Tag: Padrino Framework

Sinatra and Kaminari without any views and without padrino-helpers gem

If you have an app that doesn't have any views (for example it only responds with JSON) you still may want to use excellent Kaminari gem for paginating big data sets. Unfortunately even when you work only with JSON and you don't need any views helpers, you will still get this warning:

[!]You should install `padrino-helpers' gem if you want
to use kaminari's pagination helpers with Sinatra.
[!]Kaminari::Helpers::SinatraHelper does nothing now...

so to get rid of this, you have to add:

gem 'padrino-helpers'

to your Gemfile (even when you don't need it).

Luckily, there's a better way to do this. Add Kaminari to your Gemfile that way:

gem 'kaminari', require: %w( kaminari kaminari/hooks )

and then, either create a config/initializers/kaminari.rb or directly in your app.rb put this:

# Initialize the Kaminari gem

This will initialize Kaminari without requesting padrino-helpers.

Ruby, Mongoid and (again) memory leaks – next Identity map problem

Lately I've fixed an issue with Mongoid driver (read more about this). Memory consumption stabilized at a relatively low level until... gem update mongo. Below you can see Munin memory and CPU consumption charts from a frontend server (frontend only presents data):

There were some heavy issues on october 23d. Server went really crazy. Behavior was similar to one mentioned in previous post about Mongoid. But IdentityMap has been turned off so WTF? Well I don't know what happend, but what do I know is how to fix it. Edit your Padrino/Sinatra app file (app/app.rb) and place this in your project class:

after do

This will clear IdentityMap after each request.

I know, that this is not the best solution, however it is good enough for me - and what's more important - it works fine.

Copyright © 2024 Closer to Code

Theme by Anders NorenUp ↑