Validtions in Rails Model

Different Validations in Rails :

  1. validates_presence_of  :status
  2. validates_numericality_of :fingers
  3. validates_uniqueness_of :toothmarks
  4. validates_confirmation_of :password
  5. validates_acceptance_of :zombification
  6. validates_length_of :password, minimum: 3
  7. validates_format_of :email, with: /regex/i
  8. validates_inclusion_of :age, in: 21..99
  9. validates_exclusion_of :age, in: 0…21,
  10. message: “Sorry you must be over 21”

Including multiple validations in one line ( ‘ ,’  separated)

validates :status,   presence: true,
uniqueness: true,
numericality: true,
length: { minimum: 0, maximum: 2000 },
format: { with: /.*/ },
acceptance: true,
confirmation: true

How to open mobile view on Desktop browsers?

Actually it is very simple

1. Firstly you will have to install Mozilla Firefox browser on you stytem.
2. Install the User Agent AddOn in Firefox and restart Firefox.
3. From Tool Bar of Firefox: Tools >> Default User Agent >> iPhone

Destop firefox user Agent to open mobile view iphone, android on desktop
Destop firefox user Agent

Then this will open the iPhone view of the websites for you in desktop if it exists.
Now, If you want to view the looks of the website for other devices the go to:
Tools >> Default user Agent >> Edit User Agents >> New >> New User Agent

User Agent Firefox
Edit User Agent

and then in
Description : Example iPhone, Android, Tablet etc
User Agent : Paste the following

For iPhone :
Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16

Tablet ios :
Mozilla/5.0 (iPad; CPU OS 6_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B141 Safari/8536.25

BlackBerry8520/ Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/301

Android 4.04:
Mozilla/5.0 (Linux; U; Android 4.0.4; en-gb; GT-S7562 Build/IMM76I) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30

This UserAgent woks fine with Ruby on Rails Project using Mobile_Fu gem for creating different mobile views.

How to freeze my Rails application?, Why I Should freeze my Rails application?

Ruby on Rails allows you to “freeze” the version of Rails used by your application.

1. Following command will freeze your application to the version of Rails that is currently on server:

rake rails:freeze:gems

This command will copy the Rails files to the “vendor/rails” directory of the application. When the Rails application the it will first check for the presence of “vendor/rails” directory. If it exists, Rails will load the Rails components from the directory instead of using the main server copy of Rails.


rake rails:unfreeze

Freezing to a different version

This command freezes the application to Rails 2.2.2:

rake rails:freeze:edge RELEASE=2.2.2

Following command freezes Rails to the current development version of your application:

rake rails:freeze:edge

To Find the Rails version of your application using use this command:


After updating Rails version update your configuration file “config/boot.rb”:

rake rails:update

Ajax call on succes of the previous ajax call?

1st ajax call:

success:function (data) {
check_subs = data; //returned text
alert("This service is not for you.")
var calling_url='http:///subscription/.aspx?entrytype=ACT&entrymode=pack_w&request_attempt=' + random_uuid;
$.ajax({ //2nd ajax call
success:function (data) {
alert("Your request for pack is sent ");


Post caling in rails with link_to tag.

Http calling:

<%= link_to “Click to call”, url_for(:action => ‘your_action’, :controller => ‘your_controller’), {:class => ‘html_class’, :method => :post %>

Ajax calling:

<%= link_to “Click to call “, url_for(:action => ‘your_action’, :controller => ‘your_controller’), {:class => ‘html_class’, :method => :post, :remote => true} %>

Blog at

Up ↑