Friday, 24 May 2013

how to run rails console in production environment


We run the below command for getting into rails console.

> rails c

By default it will load the development environment. But some time you may need to run in production env to check some configuration variables.

You can run the rails console by specific environment with the below command.

RAILS_ENV=production rails console

This will load the production environment setting to the console env.

Thank You,
Uma Mahesh.

Thursday, 16 May 2013

Synchronous and Asynchronous difference

Hi,

Many of the folks are quite confused about the Synchronous and Asynchronous request in web application. May of us know that AJAX is an asynchronous request. But what does asynchronous mean?

Asynchronous request will not wait for response for an request. Let me explain with an example. 

function Namecheck(){
var avilability = 1;
avilability = get_status("/user/check_name");
if avilability == 1
{
alert('avilable');
}
else{
alert('Not avilable');
}
}

In the above case 'get_status' will send an ajax request to "user/check_name" and it will not wait for the response for that request as it is an asynchronous, there by we always get the javascript alert as "avilable". So the function will execute without ant wait for response. This is how asynchronous request will work. 

Synchronous request is the one which will wait until the complete response was received. 

Note: to over come the response issue with AJAX we will use callback to trigger a function once the complete request was done with receiving a response. 


Thank You,
Uma Mahesh

Tuesday, 14 May 2013

Email domain validation in ruby

Hi,

Most of the web applications will have registration forms and every form will have email field as the mandatory. We use regular expression to validate the email format. But some times we may come across tio validate the given email id was valid or not that means does the domain exists or not.

Below is the useful code to validate the domain name in ruby with the help of MX records.


In email_validation.rb


require 'resolv'

class EmailValidation
def self.validate_email_domain(email)
domain = email.match(/\@(.+)/)[1]
Resolv::DNS.open do |dns|
@mx = dns.getresources(domain, Resolv::DNS::Resource::IN::MX)
end
puts @mx.size > 0 ? true : false
end
end


s = EmailValidation.validate_email_domain("umamaheshvarma@gmail.com")


The above method will return true if the domain exists.


Thank You,
Uma Mahesh