Hi Friends,
In my previous blog Rails Active Records Callbacks: Part 1, I explained about why these callbacks are required and also discussed about some of the useful methods available in rails active records during creation and saving of the ...

Hi friends,
Whenever you create,save or initialize an object there are so many things available in rails that are called Callbacks or Hooks. They can be used as checks between on stage of the object to another. In this chapter I am going to ex...

Hi Friends,
In my previous blog Routes in Rails using Objects, I explained about using routes with objects. Today I am going to tell you about how we can customize the routes that are created using resources. As we know whenever we mention res...

Hi friends,
Whenever a request comes to a server, the first thing comes into picture is routes, that tells the request about which controller's action will respond to that request. When I started creating my first application one thing alw...

Handling Invalid JSON Error in Rails
Hi Friends,
Sometimes by mistake, when we send an incorrect JSON to server, the server is not able of handle the improper JSON so it throws an error, and the client doesn't get any proper error m...

Hi Friends,
In my previous blog Rails Command Line Tools. I discussed about some rails command line tools. Today I am going to tell you about rake command in rails. rake is actually a ruby version of unix's make command. It is also used to...

Hi friends,
Whenever we create an application, there is always a case where we want to have different kind of users who needs to login into the app but they have different access rights, so that some functionalities are hidden for some users and...

In programming our program must act according to our control structure, it must follow the rules and conditions which are supposed to be follow, for this we use some conditions that is known as conditional flow, by this our program do what we wan...

Validation
There must be something twirling inside your mind after seeing validations in ruby, validation
are basically used to check whether you are sending right parameters or not. i will explain you
by brief code
class School &lt...

Hi friends,
Today I am going to tell you how we can upload images in rails using carrierwave gem. It automatically creates folder inside public folder and uploads images there. You can also customize the upload location. Here is the step-by-st...

Hi friends,
Few days back I was facing difficulty in integrating recaptcha with rails so once after integrated it and I though it would be helpful for you guyz, if I mention it step-by-step as I did.
1. Open your Gemfile and add this code:
&...

Send SMS using Twilio: Rails
Twilio is a SMS gateway service that lets you send and receive SMS using your application. For testing purpose, it allows you to send SMS for free to few numbers. To start integrating twilio, you fir...

Sending Notifications on Exceptions in Rails
Hi Friends,
Let's first discuss about debugging a code. During development, suppose you have pushed some changes, then you need to test each and every functionality to check whether y...

Sending Emails in Rails using Gmail Account
For sending emails in rails,ActionMailer Class is used. Emails can be sent using any service providers like Gmail, Sendgrid, Mandrill or any other. Here we will see how we can send the emails us...

Export Data into Excel in Rails
Hi friends,
In my previous blog Import From Excel in Rails. I showed you how can we read excel records from excel sheet and store it into DB in rails. In this we will see how we can download the list in excel for...

Importing excel files in Rails
Hi friends,
Importing excel sheets and storing them into db is a very common usecase of applications. So here I am going to guide you to a step-by-step process of how to import records into db from an excel fi...

Rails: Customizing Time Ago in Words
Hi friends,
Whenever something is published to a site, we see in their posted time, it is written like about 2 minutes ago or about an hour ago. These kind of sentences displays how much time before the cont...

Rails: Scopes
Rails is made for building applications rapidly. Scope is an another example that truly admires this feature. Its use can be explained by taking an example. Suppose you have a blogging site and you want to show everywhere only thos...

Hi friends,
The popularity of Ruby on Rails now a days is so much because of its rapid development, which is possible because of its gems. For every generic functionality there is a gem available, so why not create our own gem. Today I am going ...

What friendly gem can do?
Friendly_Id is the "Swiss Army bulldozer" of slugging and permalink plugins for Active Record. It lets you create pretty URLs and work with human-friendly strings as if they were numeric ids.
Ra...

Ruby provide with the following ways by which you can invoke the method based on your requirement :
s= "ruby method"
1) Call a public instance method directly
p s.length #=> 11
2) Other way is to invoke a method dynamically in ...

Foreman is a gem (aka manager) for managing multiple processes that your rails application is depending upon when running in development environment and also has a option to move it into production environment as well. It is based on a Procfile t...

Rails Server setup with Passenger and nginx
Hi friends,
Today I am going to tell you how to setup rails server with nginx and passenger. First you need to login to your server using ssh using the command
ssh -i server_pem_key_path user@...

Strong Parameters in Rails
Strong parameters are used to prevent the action controller parameters that are used in Active Model Mass Assignment. If you want to use them, you need to white-list them. It is basically used as a security for sensiti...

default_url_options in Rails
Rails has a url_for helper, which is used for generating hyperlinks. So many times we want that a certain thing or parameter needs to be passed with each link or request to tell the controller to do certain thing...

Use of Flash in Rails
In rails, flash is also used as a session management method. Its feature is that it gets cleared after every request. It is basically used when we just want to show a message in the next request or view and don't want t...

JQuery Ajax Post in Rails
As we all know, ajax is used for saving some objects to server or requesting to server and in response, page should not be refreshed. Rails provides helper remote: true, that can be added in ruby form helpers. After a...

Cookies are objects that we use to store some information of the user in the browser like geolocation of user . It is a set of key value pair. All cookies have time of expiry after which they are just deleted from the browser usually at the end o...

Rendering xml or json data from the controller method is very easy. We have to just follow this syntax.
Example(xml):
def index
@users = User.all
respond_to do |format|
format.xml {render :xml => @users}
...

Adding Translation to a Rails Application
Hi friends, in my previous blogs related to internationalization of rails application, we have configured the i18N api and saw different types of methods to pass the locals, if you have not read thos...

Rails Internationalization : Setting locals from URL
In my previous blog, we looked in Setting rails locale from domain name, it was a good approach of detecting the desired locale from domain or subdomain, but sometimes you are not able to ...

Rails Internationalization : Setting locals from Client Requests
Hi friends, in my previous blog, we looked into Setting the Locale from the URL Params. There are some more cases where we don't want to set the locales through URLs or domains...

Rails Internationalization : Setting locale from Domain Name
For translating your application to other language, you can set I18n.default_locale to your locale in application.rb or in initializers as I told in my previous blog Configuring i1...

Filter in Rails
Filters are the methods, that run before, after or around a controller action. We can better understand it by taking an example. Suppose in a blogging site, there are groups and we want that a user can only read blogs of his gr...

Hi friends,
As we all know, rails always encourages RESTful (REpresentational State Transfer) design for resources, that specifies standards for using different kind of requests. Rails also supports this. Thus if you are using RESTful, you would...

Date and Time Helpers in Rails
Date and time selection are very common in forms for saving event times, schedules, birth date etc. Rails also provides date and time helpers for taking inputs of date, time or datetime. While dealing with date...

Uploading Files in Rails
Uploading files from a form is a very common task(i.e uploading images, files etc). As you may already know that you need to set multipart/form-data, if you want to upload files from a form. Similarly in rails, you need ...

One of the most common html elements in a web page is select box. In Rails select and option tag helper method is used to display it .
select and option tag:
<%= select_tag(:city_id, options_for_select[[Bangalore, 1], [Dehradun, 2]]) %&g...

Hi Friends,
As we know that, currently there are plenty of content based sites and we usually see a search box within that, to search any topic that is available in that site. So today we will be discussing on how to create a basic search form i...

Hi friends,
In my previous blog, we talked about customization of form helpers and how to create forms for external resources through form helpers in Form Helpers in Rails Part-3. Now we will switch to discuss on how to build complex forms in ra...

While sending an ajax request in rails sometimes we dont need to render any data back to the page . Only status 200 is sufficient to show changes in the view page then we use render :nothing option but there is an alternative to it is head metho...

Hi friends,
Previously we talked about form helpers dealing with models in Form Helpers in Rails Part-2. Today we will continue with Form Builders Customizations.
As we already discussed that objects from form_for and fields_for are instance of...

render() method in rails is used for rendering a content to the view . Its uses are:
In Controller for rendering an action
Example:
render :action => "show"
This is the most common use of render in controller . The template for sh...

Hi Friends,
In my previous blog Form Helpers in Rails Part-1, we have talked about only the basic form helpers. Today we will be discussing forms with models. As we know in MVC, forms are mostly used for creating, updating or editing models. So...