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
Using GREP in Ruby
Working with GREP in Ruby
As we know that ruby contains a lot of built in modules, in which one of this is the Enumerable module. So before preceddingon what GREP is and How it works, first lets study a little info about Enumerable module...
Migration in Rails - Part2
Hi friends,
In my last blog Migrations in Rails: PART 1 - Introduction and Creating Tables I told you what is migration and how we can create tables in migration today I will tell you some other generic queries that are used:
1. Dropp...
Migrations in Rails: PART 1 - Introduction and Creating Tables
Migrations in rails are basically used for executing DDL (Data Definition Language) statements. The main tasks of migrations are:
1. Creating tables
2. Updating Schemas
3. Altering tables
4. Dropping tables
Each migration works as a new ...
Different Types of Renders in Rails
render is used to provide response of a request in rails. There are multiple kinds of responses that you can send with request. Lets see one by one:
1) actions:
By default if nothing is specified as render, actions are rendered withing in...
Protect From Forgery in rails
The first concern for every application is its security, so rails by default provides a method protect_from_forgery, which is always present by default in your application, whenever you create a new application. i.e.
class ApplicationControl...
Transaction in Rails
As we all know in SQL transaction are used to maintain the integrity of the data, so that if there are multiple queries written, which has a condition that either all of them are executed or none. So for achieving those rails has written the wrap...
Introduction to JWT
With API becoming so popular these days thanks to SPA base applications, it was also required to keep these APIs secure. So the most popular of securing api's is token based authentication, whose flow is little bit like this:
1. In the b...
Changes Related to Active Records While Updating From Rails 3.2 to Rails 4.0
From Rails 3.2 to 4.0, there were so many things that got changed. So here I am telling you the major changes that affected the active records, and that you should take care of during updation from 3.2 to 4.0:
1) There were some inconsistenc...
Integrating SOAP in your Rails Application
Hi Friends,
Most of the large applications use SOAP for data transfer between two parties. So in rails we can also integrate SOAP support. For this there are multiple gems available. One of the mostly used gem is "savon". So here we ...
Integrating SAML with Rails Application: Part 2 ( Setting UP Local IdP server)
In my previous blog Integrating SAML with Rails Application, I told you how we can integrate SAML in your application and also told you few things regarding the Service Provider and Identity Provider. So once you have a ready Identity Provider, e...
Integrating SAML with Rails Application: Part 1
SAML is Security Assertion Mark Up Language, which was built to provide authorization between multiple identities, so that multiple services can use the same authentication.
The SAML authentication can basically happen in two ways:
A) SP In...
Things to Notice Before Upgrading Rails Application
Hi Friends,
Whenever you create an application it is never for lifetime, there is always something and better comes in the market, and once we talk about rails application, it comes pretty quickly. After every few months rails comes with a new...
Changes regarding HTTP PATCH in Rails 4
Hi Friends,
There were so many changes came with introduction of Rails. So one the major change was regarding the HTTP Patch Requests. From rails 4, whenever a resource is declared in the routes, by default it uses PATCH as primary verb...
Stashing in Git
Hi Friends,
Git is the great tool for project versioning and code management, but mostly we are unaware so many things. So here I am going to tell you what is stashing in Git.
Sometimes we are working on some code and we don't want it t...
Upgrading Rails Application From 3.1 to 3.2
In my previous blog Upgrading Rails from 3.0 to 3.1, I explained you how we can upgrade a rails application from 3.0 to 3.1. In this I am going to show you, what changes are required to update an application from 3.1 to the latest of 3.2 rails ve...
Upgrading Rails Application From 3.0 to 3.1
Upgrading a rails application directly from a lower version to a much higher version is never a good idea, so the best idea is to do it step by step. like one upgradation at a time. In my previous blog Things to Notice Before Upgrading Rails Ap...
Ruby Enumerables: (all, any, none, find)
Ruby provides a number of enumerable methods that we can pass on collections or array for performing searching, sorting etc operations.
Here I will be discussing with all, any, none and find methods:
a) all?
In this every member of the...
Making Thumbnail Image in CarrierWave
As we know that in almost all web applications we use images then be it larger images or thumbnails
So for these functionalities we use Carrierwave gem. This gem helps us with uploading images and files.
With the help of carrier wave ...
Different Equality Operators in Rails
1) ==
It is a simple equality operator, that only checks if the value of the left operand is equal to the right operand or not, so returns true or false respectively
<pre>
> x = 5
> y = 5
> x == y
=> true
> y =...
Asset Package Pipeline In Rails
The asset pipeline can be said as a tool through which we allow the Javascript files, stylesheets, and images to be prepared so that they can be used by the browser.
These processes are used to compress all the coffee script and...
Creating a random string for multi purposes in Rails
As we know that in almost all web applications we have to ammend functionalities in which we need to create a random string.
This string can contain some alpha numeric characters, numbers, lower case alphabets, upper case alphabets and etc.
...
Reading text from a file and saving in the database in Ruby
As we know that in almost all web applications we need to amend such a functionality where you need to get the content from a file stored externally in your pc. lets say this content to be a simple text content.
In these cases what we can do i...
before_save And after_destroy callbacks in Rails
Sometimes while developing applications, need arises that we have to get some operation performed either before or after the execution of some method.
For these purposes rails provide us with some nice hooks or we can say callbacks which can b...
Tap in Ruby
In Ruby, we often sum up our code in the minimum number of lines. We have a method tap which helps us to perform number of operations, which are dependent on the intermediate results.
for example.
(1..10).tap{|x|}.to_a
=> [1, 2, 3, 4...
Use of lambda, Proc and Block in Ruby
Today we are going to see the basic differences between Block, Procs and Lambda.
All these three are commonly used as inputs to some iterators like each and map.
Blocks
Blocks can't be stored ...
Arrays and Hash In Ruby
Ruby's arrays and hashes collections having indexes. They can also be said as indexed collections.
Arrays and hashes store collections of objects which can be accessed using a key.
Both arrays and hashes grow as needed to hold...
Using Dependent Destroy In Rails
As we know that all the models in our rails application are connected to one another through relations between them.
Now these relations can be one to one, many to many, many to one or one to many and etc.
Now lets see a scenario where we h...
Ruby Access Control
The Access Controls provide us the method which allows us to set access to classes , methods and other members in Ruby. They help us to bind the components to maintain the security of the methods throughout the project.
Rub...
Namespaces And Scopes in Rails
As we know that in rails, in order to reach to any page or URL we have to create routes and resources for the same.
Namespaces and scopes are wrappers which can hold our resources inside them and create the routes accordingly.
Namespaces...
find_each method with options in Rails Active Records
When creating web applications, always a need arises when we have to iterate over a large number of records.
This process is called retrieving multiple objects in batches. This can be done through find_each method.
The find_each method by d...
Active Records for Adding, Removing or Changing a column
When we create a web application we generally create models which are referred to as tables in the database. Sometimes we need to add a column to the existing table or remove an unused column from the table or just change the column. The way to d...
How to add a default value in a column through Migration in rails?
As we know that the rails migration is used to interact with the database and create schemas.
Many a time when we are creating migrations, we may forget to add a column in the table.
Or sometimes a need may arise when we have to make ...
Ruby Enumerators
Enumerator is a type of class which allows both the internal and external iteration.
List Of Enumerable Methods in Ruby:
collect
map
each
select
Collect:
It is similar to the map method and it allo...
How to use partials in Rails Applications
As we know that in almost all web applications there is a set of code which has to be executed often in many places.
Now suppose we have a header and footer which has to be used all over the project.
Now if we would write th...
before_validation and and after_touch callbacks in rails
Rails provide us with some pre-defined methods or hooks which can be invoked after or before the execution of a certain method in the object life cycle.
Callbacks are called in certain moments of object's life cycle which we will get to kn...
after_initialize and after_find Callbacks in Rails
At the time of normal operations in rails application, the objects are either updated, created or destroyed or we create our defined methods in the controller.
Rails provide us with some hooks in the object life cycle which we can invoke...
Eager Loading and Lazy Loading in Rails
Eager Loading and Lazy Loading in Rails
As we know that almost every web application has an interaction with the database to fetch records or insert records and other functions.
This can be achieved through different types o...
Redirect_to and Render methods in Rails
As we know that in rails we have models view and their controllers which act as a medium between model and view.
The normal flow between a controller and a view is to display a view corresponding to its controller action.
So this can ...
Achieving Nested Comments in Rails
Few days back, I was working on a project where I have to create nested comments on a articles and on showing the article I was needed to show all the nested comments in its hierarchy.So I used closure_tree gem to achieve that. So lets see how I ...
Fetching Single objects in Rails Applications
Fetching Single objects in Rails Applications through Active records
While creating a web application in rails we often feel the need to fetch single objects from the database.
Active records provide us with a very good quer...
Sending Email through SMTP mailer in Rails
Sending Email through SMTP mailer in Rails
As we know these days in almost every application we have the need to send mails to its users then be it for password confirmations, subscriptions etc.
So these mails can be sent through your rails...
Using Delayed Jobs in Rails
Using Delayed Jobs in Rails
When creating a web application sometimes need arises that we have to schedule some jobs during the execution of a particular method. Due to these job the render of the page has to wait until the task gets over...
Axlsx gem Integration in Rails
AXLSX gem is one the most recommended gem for the creating excel file in rails application.
To integrate AXLSX gem, we have following steps.
first we need to insert gem in our gemfile
gem 'axlsx_rails'
and run
bundle in...
Responses In Rails: Part 1
Hi Friends,
As we all know rails works on MVC Architecture, where the controllers acts as the receiver of the requests and sends the response back to the requester. There are actually 3 ways a controller can send a response :
a) render: It ...
Compare two strings by comparing the sum of their letter-Values
Description:
Compare two strings by comparing the sum of their letter-Values (char-Value).
For comparing treat all letters as UpperCase.
Empty and null-Strings should be treated as they are equal.
If the string contains other characters t...
Implementing Token Based Authentication in Rails
In modern world, most of the web applications are api based. So using api's we also need to validate the authenticity of the user. When it is a proper web application the authentication of the user is maintained using cookies and sessions. Bu...
Inspect, to_s, p and puts in ruby
In rails, sometimes we don't notice it but there is difference when you use puts to print an object and when you use just p to print an object. One thing let me clear for you, p is not a short form of puts, they both are different.&...
Installing And Using NGROK (Rails)
Installing And Using NGROK for Rails Application
NGROK allows our web application running on localhost web server to be exposed to the internet. Its like making our web application live. It creates a secure tunnel from a public ...
split ,find_index , map and capitalize methods in Ruby
Strings in Ruby have an instance method namely split that splits the given String and returns an array of substrings based on the separator given as an argument to it.
have a look at these examples:
gauravjhadiyal@gauravjhadiyal:~$ irb
2...
using return keyword within a Ruby block
As we all know,Ruby Blocks and Ruby Methods work in tandem and the output/value of the last line/expression being executed by the block is returned to the associated method .
Have a look at this example:
2.1.5 :006 > def demo
2.1.5 :0...