Showing posts with label ROR Development center in India. Show all posts
Showing posts with label ROR Development center in India. Show all posts

Monday, 12 May 2014

Using Delayed_jobs Gem in Rails 3

Consider we have a long running task like sending emails to large number of users,the user have to wait until the request is completed then only the rails application can accept another request.so it is preferable to run the long running tasks in the background,for that we can use sidekiq or resque or DelayedJob etc.Sidekiq and rescue requires redis,here we are going to use delayedjob.Lets us see how to use delayed_jobs gem in our rails application.

Add the following to your gem file.

gem 'delayed_job_active_record'

Run the bundle install command to install the gems.

The following command will create a table as it is required to have a jobs table for AR backend.

rails generate delayed_job:active_record
rake db:migrate


Then we can use .delay method to process any job in the background.

without delayed_job  

UserMailer.notification_email(self).deliver

Here we are going to remove the .deliver and add .delay to the UserMailer

UserMailer.delay.notification_email(self)


Thats it! now the process will be added to the delayed_jobs table.

But we have to start the jobs,for that use the following command by entering into your application directory. 

script/delayed_job


In staging add gem "daemons" bundle and run rails generate delayed_job.

RAILS_ENV=staging script/delayed_job start

In production add gem "daemons" bundle and run rails generate delayed_job.

RAILS_ENV=production script/delayed_job start



(203) 208-3081


Tuesday, 29 April 2014

Installing Ruby on Rails on Linux Machine

You can follow the steps below to install ruby on rails on your linux machine.Open your terminal and follow the steps below.

First we are going to install curl,we will be fetching RVM by using curl.
sudo apt-get install curl

Installing RVM:-
RVM means ruby version manager it is used to maintain multiple ruby versions.It is highly recommended to use RVM  as sometimes you may want to use earlier ruby versions(ex:- 1.8.7,1.9.3) for older projects and current version for the latest projects(ex:- 2.1) and this problem is solved by RVM,you can refer the documentation for other versions and full details .

We can install RVM using the following command.

curl -L get.rvm.io | bash -s stable

In order to source the rvm scripts file we will be using this command. 

source ~/.rvm/scripts/rvm
This command will install the dependencies.

rvm requirements
you can get the list of ruby versions available by using

rvm list known
Now we can install the required ruby version with this command

rvm install RUBY_VERSION
ex:- rvm install 2.1.0
now we can check the ruby version installed by using

ruby -v

If you want to set ruby 2.1.0 as default ruby version then use

rvm --default use 2.1.0

As both RVM and some version of ruby are installed in our machine and we can proceed with installation of rails.
we can install rails by using the following command.

gem install rails

The above command will install the latest rails version,if you want to install some other version of rails you can use

gem install rails -v SOME_VERSION

ex:- gem install rails -v 3.2.11

That's it you can check your rails version using rails -v in your terminal.

Call Us – (203) 208 3081
Write us – sales@panzertechnologies.com.