Featured
-
Installing RVM and Creation of Gemsets Part 2
In the last tutorial we learnt how to install RVM.
by dinesh.singh -
Installing RVM and Creating of Gemsets Part 1
Installing RVM and creating Gemsets can be difficu
by dinesh.singh -
Use pik in Windows
Managing multiple versions of Ruby on Windows can
by anirudh.rautela -
Using Bundler in Rails 2.3.x app
Managing Gems in Rails can be infuriating at times
by anirudh.rautela
Tags
after_sign_in_path_for method and after_sign_out_path_for method in rails
If we are using Devise gem with our Rails project, One of the common tasks that a developer wants to do is to show a custom page when a user signed in .
So here our intention is to modify the default Devise's behaviour when a user signed i...
None and readonly methods in active records rails
Hi friends,
There are some special kinds of methods in active records rails, that can be used for different purposes. Here I am explaining two of them
1. none method:
none method as its name suggests returns no records. So it is used in ...
yield in ruby
Hello friends,
Today while programming in ruby and I came to know about the yield word in ruby, how important this word is in ruby, I will discuss some example where to use yield in ruby. As while programming in ruby you must have used blocks ...
Implementing file upload functionality with PapaerClip Gem
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...
Using Braintree As Payment Gateway (Part 1)
There are several player in the market which can be used as payment gateway and it is not always easy to choose one . Thus today I would like to give you an overview of well known payment gateway i.e Braintree which is a subsidiary of Paypal. The...
Difference between render And redirect_to
render and redirect_to works in the similar way in your web browser , as they both takes you to a new page but the only difference between them is :
When you call render it creates a complete response which is sent to your browser.
...
Collections in Ruby
Whenever we code in any language, the first question arises that, what are the important Data collection in the corresponding Language contains.
As we have Ruby language with us. We have some nice Data Collections here.
Array
Hash
Se...
Policies in Rails
For an application we need some authorization method, Policies in rails is one of them.
There is one library Pundit used for authorization.
Pundit gem uses object oriented design and Ruby classes.
To start with add this gems into your Gemfil...
Draper decorator (rails refactoring)
In this tutorial we will have a look on Draper gem, which helps us decorate our views more like in object oriented approach. Its a great gem and provides us lots of options to decorate single object and collection of objects. We discussed present...
Variables in Ruby
There are 4 types of variables in Ruby: Global, Local, Instance and Class. Ruby is a language where a variable can contain any type of object, you can assign a string to a variable which has previously an integer value. As in ruby we generally do...
Integrating Omniauth with Devise in Rails
In this article we will going to give privilege to users to log in by their social networking profiles.
Here we will discuss to log in by facebook.
First we will going to install Devise gem.
Now when we have installed and integrated Devi...
Devise gem in Ruby on rails
Devise gem is one of the highly recommended gem used in Ruby on Rails.
It has many features such as Email sending, locking User, Authenticating user and many more.
To install Devise gem, you need to specify it in your Gemfile
g...
Writing Skinny Controller In Rails
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...
Form objects with Reform gem (Rails refactoring)
We have been discussing refactoring in our previous posts. Next to our refactoring pattern, we will discuss few gems that can be used to improve our coding style.
In my last post i explained form objects pattern. Form objects are not...
Decorators in Rails
We use Decorators for cleaning up view logic and models of a rails application. So if we use decorators, models and views would be less complex. When we use decorator for a project we might have a 1:1 mapping between models and decorators which m...
Special Finders in Ruby on Rails
Rails has different types of finder methods that reduces your great amount of time. Suppose you want to create a record only if it doesn't exist already, your first approach would be first find the record and if is not already exist then you ...
Workers in Rails
Sometimes to improve the performance of application we need to schedule some slow tasks into background, that is where Workers comes in the picture. So instead of executing slow tasks during the HTTP request execute them into background.
In ...
Using rolify devise and cancan gem together for user authorizations and access in rails
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...
Form objects pattern (refactoring)
In previous tutorial we discussed refactoring code and decorators pattern. In this tutorial we will take our discussion further to form objects pattern. We use forms in our application to take inputs from user. The form data is received in our co...
dependent: :destroy in rails models
Let's consider this example.We have two tables events and tags in our database having a many-to-many relationship between them.So We create a third table taggings behaving as a junction table .So taggings table has a many-to-one relationship ...
Interactor in Rails
Ruby on Rails Interactor
Before interactor we use to write complex business logic in some class in the ActiveRecord /models directory and that class can have too many responsibilities so while testing we could stuck between tediously slow te...
Difference between reset and drop in rails
We often use rake db:reset command for recreating the database, instead of conventional 3-steps for doing the same.
rake db:drop (dropping the Database, wipe away all your data)
rake db:create (Create the Database)
rake db:migrate (Runs...
control structure
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...
Class Methods And Object Methods
Object Methods:
Object Methods are thode methods which we have to explicitly define in the class.
First we have to create an object of the class and then we call the object methods.
Example:
class Object
d...
Model View Controller Architecture (MVC)
MVC Architecture
MVC architecture is a software constructing or designing pattern which is widely used these days to build software applications or web based applications. MVC breaks an application into three main parts namely Model ,View a...
Reading content from file and saving it to database in Rails
Hi friends,
Sometimes we want to read the content from a file and save into our database. So we can achieve this in rails we do following:
1) First you need to add a column in your model where you want to save the content ...
form_for method in rails
Both form_for and form-tag are Rails helper methods. Whenever we want to build a form containing various elements like text-fields,text-areas,labels etc, we simply need a form builder object.
form_for rails helper method just do that, it provi...
validations in ruby
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 <...
Select Vs Pluck in Rails
In this tutorial we will see how we can use pluck and select in rails active record queries.
Select is used to fetch records with specific attributes. It returns ActiveRecord::Relation object.
Project.select(:id)
Project...
Variable Types In Ruby
1.Global Variables
2.Instance Variables
1.Global Variables:
They start with a $ sign.
If we do not initialize values to global variables , they take a default value of nil.
Examp...
Scopes in rails
A unanimous definition of a scope in rails can be termed as a succinct way of creating database queries. We define a scope in a Model class in the purview of MVC architecture.
It's syntax goes like: scope(name, body, &block) .
...
Enumerators in Ruby
Enumerable Methods in Ruby
Ruby has a list of enumerable methods or we can say enumerators that have specific functionalities which can be applied on various collections like array ,hashes etc
Map
Select
Each
Collect
Map
...
Image upload using carrierwave in rails
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...
Integrating Recaptcha in Rails with Devise
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:
&...
Lambda ,Block and Proc
About lambda:
Lambda are just like objects.
It is just like a regular function whose last statement is it's returns value.
Syntax for lambda : lambda = lambda {}
Example1:
l = lambda{"hello"}
puts l.call
...
Access Controls with examples in Ruby
Access controls refers to the methods which allow you to set the access to classes, methods and other members. They are used to encapsulate the components so that we can maintain security of these methods throughout the project.
Ruby gives us ...
Difference between a Symbol and String in Ruby
A string is placed either within single quotes i.e ('') or double quotes i.e ("") whereas on the other hand, a symbol is preceded by a colon i.e (:).
A string has a variety of methods to use but contrary to that a symbo...
Rescue Exception
An exception is an instance of the class Exception or a descendant. In ruby to rescue exceptions we do something like this:
def process_request!
#some code here
rescue
Rails.logger.error { "#{e.message} #{e.backtrace.join(...
array and hashes in ruby
Ruby array is a list of elements that can be of any type either string or integer. Hence, In ruby it can be integer or string.
we can declare array by placing the elements inside the brackets like;-
arr = [1,"array",2,3,"h...
Rails code patterns Decorator/Presenter (Refacotring)
In my previous article i explained when we should refactor code and how to refactor. Lets take our discussion further to decorator/presenter pattern. Decorator/Presenter pattern have been overly used in rails community. There is a thin line betwe...
Sending SMS using Twilio: Rails
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...
Refactoring Code in Rails
While developing some functionality, sometimes we take shortcuts to finish it on scheduled delivery time. We give less time on code standards and more on functionality. But with code growth we have perfect opportunity to clean our code and follow...
Rack in Rails
Rack is a middleware, it provides an interface for a web server to interact with a web application. To understand how rack is used to interact with web server and rack(rails) application, lets first understand the request-response cycle. Client r...
Exception Notifications via email in Rails
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
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...
Blocks in Ruby
A block is a chunk of code that we put inside do..end or {}. You can use any of the both ways. But multiline block (do..end) is preferred over inline({}) block.
Example of block:
multiline style#
["red", "green", "yellow"].ea...
Array and operations on array
Array is used to keep collection of objects. Array in ruby can have any type of objects together. Using array in ruby:
>> a = []
>> arr = [1, 0, 7]
>> arr[2] # => 7
>> arr.size # => 3
>> arr = ["stri...
Using super in ruby
With inheritance in ruby we can share parent class behavior to child classes. We can also override these methods in child classes.
A built-in function called super is provided by Ruby. This method allows us to call methods up the inheri...
Inheritance in Ruby
One of the fundamental aspects of Object-oriented programming is inheritance. Inheritance lets a class inherit properties from another class. Child class acquires behaviours from its parent class. This means the child classes will automatically h...
Export Into Excel in Rails
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...