Usage

newdark Jan 4, 2012

I use this in views when I need to join a array of objects from a sql request here is a basic version of what I mean.

==== Code example

<%= @blogs.map{ |blog| blog.comment }.join(" | ") %>

Links and basic explanation

dancinglightning Jan 2, 2012 3 thanks

This function, available on any Base derived class, allows eager loading. So when iterating over a result, all the data can be pre-cached, reducing the number of queries from 1+x to 2.

Several ways to use this include:

Post.includes(:author).where(..)

Post.includes([:author, :comments]).where(.....

Recommendations

newdark Dec 31, 2011

I would just use the path_to_image. I find that this is what works best. As it says above it can create problems.

Here is my code

==== Code example

def background_path(background)
if background
  path_to_image background.file_name.normal
else
  path_to_image "background_previ...

Use kill 0 to find out if process is running

artemave Dec 29, 2011

==== is_running.rb:

#!/usr/bin/env ruby

pid = ARGV[0].to_i

begin
Process.kill(0, pid)
puts "#{pid} is running"
rescue Errno::EPERM                     # changed uid
puts "No permission to query #{pid}!";
rescue Errno::ESRCH
puts "#{pid} is NOT running.";...