Showing posts with label gems. Show all posts
Showing posts with label gems. Show all posts

Friday, October 26

Kaminari - Pagination gem for Rails3


Going down the line of Rails history, I was one of those people who admired the in-built pagination feature of Rails. Then later on as we progressed to Rails2 this was plugged out and that's when will_paginate got popularized as both gem and plug-in. It became part of every application that I had built of course varying with different CSS, styles. With advent of Rails3 and unsupported will_paginate had pushed us to move on with alternatives... here come Kaminari

So straight away, jumping on to the point it's pagination gem supporting Rails3. Kaminari is based on Scope & Engine (like rails engine!). It is simple, powerful


  1. Scope based API
  2. I18n customizable helper
  3. ORM & Template engine supported
  4. Supports HTML5
  5. Flavored with themes


There are quite number of themes, recipes available for Kaminari. For users coming from will_paginate there are two striking difference to be noted in implementation

Considering we are paginating over the list of posts....

will_paginate
@posts = Post.paginate(:page => params[:page], :per_page => 10)
kaminari
@posts = Post.page(params[:page]).per(10)

On to the views...

will_paginate
will_paginate @posts
kaminari 
paginate @posts

Kaminari - https://github.com/amatsuda/kaminari
Recipes - https://github.com/amatsuda/kaminari/wiki/Kaminari-recipes


Monday, March 2

"memcached" "libmemcached" gem installation for rails app

It's been so hectic with the installations on ubuntu.

sudo apt-get install memcached

then I realised that "libmemcached" also needed. Got the latest tar http://tangent.org/552/libmemcached.html and installed.

then went on to install the "memcached" gem.

Unfortunately, this did not go as expected but raised lots of issues!

rlibmemcached_wrap.c: In function ‘_wrap_MemcachedSt_next_distribution_rebuild_set’:
rlibmemcached_wrap.c:5835: error: ‘struct memcached_st’ has no member named ‘next_distribution_rebuild’
rlibmemcached_wrap.c: In function ‘_wrap_MemcachedSt_next_distribution_rebuild_get’:
rlibmemcached_wrap.c:5858: error: ‘struct memcached_st’ has no member named ‘next_distribution_rebuild’
rlibmemcached_wrap.c: In function ‘Init_rlibmemcached’:
rlibmemcached_wrap.c:11380: error: ‘MEMCACHED_SERVER_MARKED_DEAD’ undeclared (first use in this function)
rlibmemcached_wrap.c:11380: error: (Each undeclared identifier is reported only once
rlibmemcached_wrap.c:11380: error: for each function it appears in.)
rlibmemcached_wrap.c:11411: error: ‘MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS’ undeclared (first use in this function)
make: *** [rlibmemcached_wrap.o] Error 1

After googling across and friends suggestions, could solve the problem. The problem seems to be with the latest versions of the libmemcached and also gem memcached. I cleaned up the mess and repeated the trial with the following combination.

RubyInline(3.8.1);
memcache-client (1.6.3);
memcached (0.13);
libmemcached (0.25.14);

and things are back to normal :)
Hope this would save somebody's time!

References:

http://rubyforge.org/forum/forum.php?thread_id=31257&forum_id=20894
http://blog.evanweaver.com/articles/2009/01/24/secret-codes/

Tuesday, December 11

Ruby on Rails Installing Ruby

Though you continue to work/experiment more on the online ruby editor, today we see how we would install the ruby on windows OS.
Recollect "Ruby is portable, which means can be installed on all OS's possible"

Ruby Installer for Windows. Download the executable ruby186-25.exe and double-click this file to install Ruby on your PC. (Accept all the defaults.)
Once you have installed your Ruby software, the System Environment Variable path is already set to point to the bin folder of Ruby. The installation also includes the First Edition of Programming Ruby book and the SciTE editor.

Just recollect what we had done and what's the Ruby Environment looks like.

Assuming that you installed Ruby in the folder c:/ruby, then the installation creates a number of sub-folders. See the list below.

c:/ruby/bin : Here the Ruby executables (including ruby and irb) have been installed.
c:/ruby/src : Here you get the Ruby source code.
c:/ruby/lib/ruby/gems : Here are the Ruby-Gems.
c:/ruby/lib/ruby/1.8 : Here you'll find program files written in Ruby. These files provide standard library facilities, which you can require from your own programs if you need the functionality they provide.
c:/ruby/lib/ruby/1.8/i386-mswin32 : Here you find architecture-specific extensions and libraries. These files are C-language extensions to Ruby; or, more precisely, they are the binary, runtime-loadable files generated from Ruby's C-language extension code, compiled into binary form as part of the Ruby installation process.
c:/ruby/lib/ruby/site_ruby : Here you store third-party extensions and libraries. This include your own code or some third party.
c:/ruby/samples/RubySrc-1.8.6/sample : Well, here you will find some sample Ruby programs.

From now we can also execute ruby snippets on the locally installed SciTE editor.
Open the Editor: start/Programs/Ruby-186-25/SciTE.
Press F8 to open an output window.

Create a folder named, say. rubyexamples on your C:\ and will keep all our programs in this folder. Let us repeat the our first program, that we had done yesterday online. That is

puts "Hello World!"

Now save the file as "hello.rb" under c:\rubyexamples folder. Note all ruby source files have the .rb extension.

Pressing on F5 would execute the program and outputs the string "Hello World!" on right side window.

  1. # hello.rb
  2. puts 'Hello'

Alternatively you can also type command "ruby hello.rb" to execute the hello.rb file.

Having installed the ruby on local system now repeat the yesterdays examples and practice more for better understanding.

Download the pdf version of Installing Ruby post.