Monthly Archives: April 2014

Add custom style for active admin boolean fileds

Sometimes you need to add custom styles in your active admin as per project requirement.

You can do that just adding few method in your initializer file active_admin.rb


# It extends activeadmin to show pretty boolean values
# config/initializers/active_admin.rb

 module ActiveAdmin
  module Views
    class TableFor
      def bool_column(attribute)
        column(attribute) { |model| model[attribute] ? '✔'.html_safe : '✗'.html_safe }

      def seller_column(attribute)
        column(attribute) { |model| model[attribute] ? 'Yes' : 'No' }

    class AttributesTable
      def bool_row(attribute)
        row(attribute) { |model| model[attribute] ? '✔'.html_safe : '✗'.html_safe }

      def seller_row(attribute)
        row(attribute) { |model| model[attribute] ? 'Yes' : 'No' }

Use in active admin:

# example
# app/admin/user.rb
ActiveAdmin.register User do
  index do
    column :name
    column :email
    bool_column :admin
    seller_column :seller
  show do
    attributes_table do
      row :name
      row :email
      bool_row :admin
      seller_row :seller

That’s it. Happy coding 🙂

Install Oracle Java 7/8 (JDK and JRE) In Ubuntu 14.04

You can install Oracle Java 8 (JDK8 and JRE8) In Ubuntu 14.04 easily.

Add PPA repository and install Oracle Java 7/8 using the following commands:

Oracle Java 7:

 sudo add-apt-repository ppa:webupd8team/java
 sudo apt-get update
 sudo apt-get install oracle-java7-installer 

Oracle Java 8:

 sudo add-apt-repository ppa:webupd8team/java
 sudo apt-get update
 sudo apt-get install oracle-java8-installer 

Check installation:

 java -version

 javac -version

Happy coding 🙂

Install Ruby on Rails in Ubuntu 14.04 LTS

Here is step by step instruction on how to set up ruby on rails in ubuntu 14.04 LTS

Installing Ruby using RVM:

First you have  to install  some dependencies for Ruby.

sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev

Now install ruby with RVM using those commends:

sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
curl -L | bash -s stable
source ~/.rvm/scripts/rvm
echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc
rvm install 2.1.1
rvm use 2.1.1 --default
ruby -v

Installing Rails:

Rails comes with so many dependencies like NodeJS

To install NodeJS, we’re going to add it using a PPA repository:

sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

Now run for install rails:

gem install rails
rails -v
# Rails 4.1.0

Setting Up MySQL:

You can install MySQL server and client from the packages in the Ubuntu repository.

sudo apt-get install mysql-server mysql-client libmysqlclient-dev

Setting Up PostgreSQL:

For PostgreSQL, you need to add a new repository to easily install a recent version of Postgres 9.3.

sudo sh -c "echo 'deb precise-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
wget --quiet -O - | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-common
sudo apt-get install postgresql-9.3 libpq-dev

For postgres you need to set up a user.

sudo -u postgres createuser chris -s
# If you would like to set a password for the user, you can do the following
sudo -u postgres psql
postgres=# \password salayhin

Test your settings for new install:

#### If you want to use MySQL
rails new new_app -d mysql

#### If you want to use Postgres
rails new new_app -d postgresql

# Move into the application directory
cd new_app

# If you setup MySQL or Postgres with a username/password, modify the
# config/database.yml file to contain the username/password that you specified

# Create the database
rake db:create

rails server

All done. Now visit http://localhost:3000 to view your new application.

Enjoy. Happy Coding 🙂

Add bootstrap to your rails app without gem file

If you want to add Twitter Bootstrap without gem file, follow those steps:

Download Bootstrap
Direct download link Bootstrap 3.0.0
Or got to

Copy CSS Files:

to: app/assets/stylesheets

Copy Js Files:

to: app/assets/javascripts

Append bootstrap CSS to application.css:

Append to: app/assets/stylesheets/application.css
*= require bootstrap

Append bootstrap JS to application.js:

Append to: app/assets/javascripts/application.js
//= require bootstrap

That’s it.