Library not loaded after postgresql gem installation


library not loaded: @@HOMEBREW_PREFIX@@/opt/openssl/lib/libssl.1.0.0.dylib (LoadError)

 Referenced from: /usr/local/lib/libpq.5.dylib


export DYLD_LIBRARY_PATH=/Library/PostgreSQL/9.3/lib

ArgumentError: invalid byte sequence in US-ASCII


Installing some gem and you got this error?

I was trying to install Devise:

Using devise (2.1.2) from (at master)
ArgumentError: invalid byte sequence in US-ASCII
An error occured while installing devise (2.1.2), and Bundler cannot continue.
Make sure that `gem install devise -v ‘2.1.2’` succeeds before bundling.


export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export LANGUAGE=en_US.UTF-8

How to install Capybara on Linux


Using the Capybara on Linux, you need to install some dependencies.

You may get some errors like these:

Installing capybara-webkit (0.12.1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/home/franzejr/.rvm/rubies/ruby-1.9.2-p320/bin/ruby extconf.rb

Gem files will remain installed in /home/franzejr/.rvm/gems/ruby-1.9.2-p320@indica/gems/capybara-webkit-0.12.1 for inspection.
Results logged to /home/franzejr/.rvm/gems/ruby-1.9.2-p320@indica/gems/capybara-webkit-0.12.1/./gem_make.out
An error occured while installing capybara-webkit (0.12.1), and Bundler cannot continue.
Make sure that `gem install capybara-webkit -v ‘0.12.1’` succeeds before bundling.


`ensure_application_exists!’: Xvfb not found on your system (Headless::Exception)

group :test,:development do
     gem 'capybara'
     gem 'capybara-webkit'

Firstly you need to use the capybara-webkit and install QT dependencies in your OS.


sudo apt-get install libqt4-dev libqtwebkit-dev

Ubuntu 10.04 LTS

sudo apt-get install libqt4-dev

Debian Stable

sudo apt-get install libqt4-dev


yum install qt-webkit-devel

Fedora 16

yum install qtwebkit-devel

If you are using a recent version of Fedora, the qmake executable is now called qmake-qt4. This will cause the gem installation to fail. So you need to add an environment variable your profile or the system profile.

export QMAKE=/usr/bin/qmake-qt4

Gentoo Linux

emerge x11-libs/qt-webkit

About QT installation you may check here.

You will need to install  xvfb and also use Headless gem. Headless is the Ruby interface for Xvfb. It allows you to create a headless display straight from Ruby code, hiding some low-level action. It can also capture images and video from the virtual framebuffer.


Sending e-mails with :sendmail in Rails 3


If you have a Linux Server and you want to send emails in your Rails Application using your own email server please check this. We are using ssmtp.

Put this in your environment.rb:

ActionMailer::Base.delivery_method = :sendmail
        ActionMailer::Base.sendmail_settings = {
          :location => "ssmtp",
          :arguments => "-i"

Common Mistakes

Errno::EPIPE: Broken pipe

Maybe cause you are using the argument “-t” rather than “-i”.

SSMTP is a simple and powerful way to send e-mails, mainly now in your rails application. = )

Why to Create a Seeds File?


If you are beginner in Ruby on Rails you maybe think If there is some easy way to populate you database. The answer is: Yes! Using Rails you get a lot of productive and keep your focus on the application design. As you know, the Rails uses the design paradigm convention over configuration, which seeks to decrease the number of decision that the developers need to make. With this in mind, if you look at your rails application schema, we can see the file seeds.rb .

At this file, you may put your data which you want to populate your database.

For example:

User.create(:name=> "Harold Marcelo", :age=>30)
User.create(:name => "Jefferson", :age=>28)
User.create(:name=>"Little Boy", :age=>20)

Place.create(:name=> "School")
Place.create(:name=> "Church")

rake db:seed 
#Load the seed data from db/seeds.rb
rake db:reset
Drops and recreates the database from db/schema.rb for the current environment and loads the seeds.

Now, you can create your administrators, for example. I need to migrate an application and I’ve created a file which contains all the old database,I think this is not the purpose of the seed, but you can use it for things like this too.

Factory Girl and the Builder Pattern


You want to test your code, for example, you will do an Integration Test. At each time We will really create our objects?
Using factories, you will define it just once. With this in mind, you can have focus on test. We want keep focusing on our tests. Factory Girl is widely used and implements the Factory Pattern.

FactoryGirl.define do
  factory :user do
    sequence(:name) {|n| "Name_#{n}"}
    sequence(:email) {|n| "Name_#{n}"}
    sequence(:password) {|n| "password_#{n}"}

# Let's define a sequence that factories can use.  This sequence defines a
# unique e-mail address.  The first address will be "",
# and the second will be ""
Factory.sequence :email do |n|

These factories can be used like so:

@user = FactoryGirl.create(:user)

Factory Girl gem

Like Factory Girl, we have others gems with the same purpose:

  1. Foundry (
  2. Machinist (
  3. ObjectDaddy (

With the Factory Pattern we can create several different but related kinds of objects in one step. But if You cannot create a lot of objects in a single step,maybe You will use the Builder Pattern. The Factoy Pattern can be seen as a simplified version of the Builder pattern. The Builder Pattern isn’t used in Ruby On Rails.

Bricks  is a hybrid gem with an Object Builder/Factory implementation.

Testing Mailers with RSpec


Important Gems:

1)E-mail Spec


3)Shoulda Matchers


email = UserMailer.create_signup("", "Jojo Binks")
email.should reply_to("")

Sending e-mails successfully

it "Should send e-mails successfully" do
        lambda { RegistrationMailer.register(@clients) }.should_not raise_error
it "Should send e-mail to alll admins" do
        admin_emails =
        @produts.each do |produt|
 do |admin|
            admins_emails <<
        lambda { SalesMailer.send_all(@products).should deliver_to(admins_emails) }