Finding or Building a New Object In Rails Through Active Records
Active records provide us with some methods which we can use in our database
to find or create objects automatically without having to fire two queries.
These methods run 2...

Active records provide us with ways to set constraints in our queries to specify the order in which we have to get the records from the table.
This can be done through the following ways:
order
This method is used to get recor...

Active records gives us different ways to retrieve single objects from it.
Those methods with examples are given below :
find
The find method allows us to retrieve a single object or we can say single record from the database ...

Migrations in Rails
Active records provide us with a very useful feature to change or alter our database schema in ruby on rails.
Through these migrations we can make necessary changes to our database and make changes in our tables and rows...

CRUD Operations in Rails
Before understanding CRUD operations in rails we will see what are active records. Active records point to the models of MVC architecture. Model is the component of mvc architecture which is responsible for persisting ...

Uploading a file in rails through Paperclip
As we know these days almost all the applications have the requirement to upload files to the application then be it an image , a video or any other file. I am writing this blog to share with you all...

Hi friends today I am going to guide you how you can make our controller skinny by following some basic object oriented approach in rails. Often we start writing our program business logic in our controller thus making mess of our controller as t...

Ruby supports both Strings & Symbols.
String being mutable & Symbols being immutable cater to different needs.
We can convert String to Symbol & Symbol to String at any time.
To convert a string to a symbol, we can use inter...

If you want to extract only the date, we can use the strftime method of Time/Date class, as
2.1.5 :055 > DateTime.now.strftime('%d/%m/%Y')
=> "12/30/2015"
(Here d is used to display date, m displays month and Y display the ye...

Rails provide us many features which are native to Rails and not ruby.
We can ordinalize a date in rails with a method provided by active_support known as ordinalize.
If we want to ordinalize today's date we can write :-
2.1.5 :01 > ...

There are number of ways to get the names of the all the months in the current locale. I am using the Ruby I18n gem which comes along with Rails.
This gem provides number of methods to perform these localisation tasks.
To get the month ...

In rails it is possible to to view Routes for a particular resource or Controller .
It can be done in the following ways :
1>
rake routes CONTROLLER=name_of_controller
ex:-
rake routes CONTROLLER=users
<2>
...

1> For this we should first confirm the ruby version we are currently on
rvm current
(ruby-2.2.3)
2> To view the list of available gemsets before selecting a particular gemset, we can type
rvm gemset list
gemsets for...

1> We need to install RVM before we can install Ruby, because RVM is a version manager and it will help us to install & manage different versions of Ruby on the same system and easily switch between them.
To install RVM we first need to...

1> 'each' will loop through each element of the array and evaluate whatever is return inside the block, but it returns the original array without any change.
a = [5,10,15,20]
=> [5, 10, 15, 20]
a.each {|t| t+2}
=> [5, 10, 15, 20...

While getting date in rails we do have a requirement where we need to show suffix attached to date like 2nd,3rd etc. There is no direct rails date function to get the same so in order to get date in the following format
Thu, Nov 5th 2015
...

There was a requirement of hiding all the wesite URL in a message except for a particular one. While looking for a solution I came across a particular solution which I think might help other .
params[:meal_note] = params[:meal_note].gsub(/...

In rails we can apply limit and offset to arrays in different ways.
1> Using "slice" method.
slice takes 2 arguments, the first one being the "starting_index" & the second one is the "number_of_elements".
syntax :-
arrayob...

Unicorn is an HTTP server for Ruby. It is designed to be used in production environment unlike Webrick which is designed to be used at the time of development on local machine. Because it is very fast, efficient and offers lots of good features l...

Active Record gives many predefined validation helpers which you can use directly in your class. These helpers provide us rules which can be commonly used as a validation rules. So if the validation fails, a error message is added to object error...

What happens when the user views a form in the browser for a resource, rails application creates a random string as a authenticity token and store that random token in the session and when the form generates, it places that token in the form as a...

While working in rails we make use of partials very often and there are case where we make use of same partial for different scenario. We try to achieve the same by passing default parameter for some unwanted variable which might case issue. Pass...

Difference Between nil?, empty? and blank? in Rails :-
To understand the difference between these three methods you have to look at each of them individually.
In Ruby nil? is a standard method that can be called on all objects and returns...

If you are using rvm and want to load project specific ruby version and gems automatically when you access the project directory, for this you can use a very simple command
rvm --create --ruby-version use ruby-version-number@gemsetname
ex...

Group By : As we all know that group by in any RDBMS provides us with a way to get aggregate of rows based on any particular column. Taking it in point of rails the enumerable class in Rails contains a method named 'group_by'. This method is a pu...

Meaning:-
Active Record Observers means a callback or a trigger which will get called in the life cycle of active record object. This is used for the purpose of reducing the burden on model's functionality which is not directly belongs to model....

Generally we got errors at the time of development so logs are the best place to find out the errors. Its easy to deal with log file on our local machine but if there is a live site and we have to check out for logs and logs are getting larger so...

This library is used to create pdf from html.
Steps to install:
#Install wkhtmltopdf library in ruby by using below command:
apt-get install wkhtmltopdf
#Use below command to find the path. This path need to add in in pdfkit.rb[in i...