Segmentation Fault while doing bundle install

I recently encountered this error of segmentation fault while doing bundle install in one of my rails application.

After a bit of googling I found out its an issue with ruby 1.9.3.

Here is the solution:


rvm pkg install iconv
 rvm pkg install openssl
 rvm reinstall 1.9.3 --with-openssl-dir=~/.rvm/usr --with-iconv-dir=~/.rvm/usr


Resizing the image without chaning its dimensions using paperclip


In a recent application, the need of the hour was to reduce the file size of an image without changing its dimensions.

Now, this can be acheived by reducing the quality of the image.

ImageMagick library has a “convvert” command which does exactly the same..

for eg(on the terrminal) : convert image1.jpg -quality 10 image2.jpg

image1.jpg—>original image

image2.jpg—->final image


According to the paperclip wiki there is a :quality parameter which is allowed.

I tried that but for some reasons , I was not able to get it running.

I also tried using :convert_options but it did not work too.


Thus , I wrote my own processor and got the stuff working. Here is the model and processor code :

#######Model code###########

class Passet < ActiveRecord::Base
attr_accessible :caption, :markup, :media_passet, :pcontent_id
has_attached_file :media_passet,
:styles => {
: original => {
:geometry => “256×256<“,
:processors => [:qresize]
belongs_to :pcontent


###################Processor code########################

make a file called qresize.rb in #{Rails.root}/lib/papaerclip_processors

The path is mentioned because this path is loaded automatically….

module Paperclip
# handles compression of image by reducing its quality
class Qresize < Processor
def initialize file, options = {}, attachment = nil
@format = File.extname(@file.path)
@basename = File.basename(@file.path, @format)
def make
src = @file
dst =[@basename, @format])
parameters = []
parameters << “:source”
parameters << “-quality 10”
parameters << “:dest”
parameters = parameters.flatten.compact.join(” “).strip.squeeze(” “)
success =“convert”, parameters, :source => “#{File.expand_path(src.path)}[0]”, :dest => File.expand_path(dst.path))
rescue PaperclipCommandLineError => e
raise PaperclipError, “There was an error during the Size Reduction  for #{@basename}” if @whiny


This is a general code for image resizing and probably at this stage, we may not require to write a processor.

But the advantage of doing this is that we can extend this to do a lot more as and when requirement comes.

Also, we can handle our video and audio processing by this easily.

The other option is to pass a block(lambda or Proc) to :styles hash but I personally feel this is a much cleaner approach.


Hope it helps.

PreProcessing in Paperclip


If at all you want to do any kind of prepreocessing on attachments using paperclip then here is a simple(not wen i did it for the first time…) way of getting a TempFile object and doing whatever you want.

Here I set the size of image (actually reduce the original size into half)


class Passet < ActiveRecord::Base
attr_accessible :caption, :markup, :media_passet, :pcontent_id
has_attached_file :media_passet,
:styles => {

: original => {
:geometry => { |instance| instance.set_size },
:quality => 10

belongs_to :pcontent

def set_size

ori_img =Paperclip::Geometry.from_file(self.media_passet.queued_for_write[:original].path)



Here I reduce the dimensions if the image and reduce the quality too.

This way, I can save a 1.1MB image as 39.2KB image,

It it what I required,and I hope this will give you a hint about your own application.


Hope it helps.

PS: there are many other(mayb elegant solutions) which can be found on paperclip github page whose link I have posted above.

Installing sun (oracle) jdk in precise pangolin..

Finally, after doing many things unsuccessfully,

this method works for me:

sudo rm /var/lib/dpkg/info/oracle-java7-installer* 
sudo apt-get purge oracle-java7-installer* 
sudo rm /etc/apt/sources.list.d/*java* 
 sudo apt-get update 
sudo add-apt-repository ppa:webupd8team/java 
 sudo apt-get update 
sudo apt-get install oracle-java7-installer

Rails and attr_*

There is a small gotcha in rails attr_accessible method in ruby.

  • If there are no attr_accessible attributes on a model it’s open, any attribute can be written with .update_attributes() or a similar mass-assignment function.
  • If there is even one attr_accessible the model is closed except for those attributes defined to be attr_accessible.

So there is an implicit toggle involved in attr_accessible as well as the actual desired functionality of allowing an attribute to be mass-assigned

Creating virtual hosts in apache in local machine

In this post I show how to create virtual hosts on apache and run multiple rails apps on your local machine with names like

In the previous post I had shown how to deploy rails apps on local machine with apache web server

My software stack:

  • Ubuntu 11.04
  • ruby 1.9.2 p290.
  • Rails 3.1.10
  • rubygems 1.8.10

Lets start!

First we have to enable virtual aliases on the Apache S

sudo a2enmod vhost_alias

Now I assume that the rails app is at the location:



We first create a virtual configuration file:

Tyep the following in terminal:

sudo gedit /etc/apache2/sites-available/mydomain

Copy the following settings to your file:


<VirtualHost *:80>

DocumentRoot /home/username/Desktop/rails_apps/my_rails_app/public
<Directory />
Options FollowSymLinks
AllowOverride All
<Directory //home/username/Desktop/rails_apps/my_rails_app/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

<Directory “/usr/lib/cgi-bin”>

AllowOverride None

Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch

Order allow,deny

Allow from all



ErrorLog ${APACHE_LOG_DIR}/error.log


# Possible values include: debug, info, notice, warn, error, crit,

# alert, emerg.

LogLevel warn


CustomLog ${APACHE_LOG_DIR}/access.log combined


Alias /doc/ “/usr/share/doc/”

<Directory “/usr/share/doc/”>

Options Indexes MultiViews FollowSymLinks

AllowOverride None

Order deny,allow

Deny from all

Allow from ::1/128



Important to note here is to change ServerName as per your convinince and Directory to your public of rails app.

Once this is done,

type the following to open the hosts file:

 sudo gedit /etc/hosts


In this file, copy the following code:


replace domain name with your desired name.

This is what you will use in browser to access the page

Activate your domain and reload the Apache Server to enable settings
Enable the site

a2ensite domain-name


Reload Apache2

/etc/init.d/apache2 reload


Finally test your app by typing and see the magic !!!