Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 

Optimistic locking in rails

Optimistic locking is used to restrict updation of a record by multiple user at the same time . For example we have two user u1 and u2 and both of them is trying to edit the same record from a model City . While u1 is editing the record u2 c...

Validating Associated models in rails

Hi Friends, I am here again with one more topic in rails that is validates_associated. So as we all know that associations are a major part in every kind of Relation Databases. So what happens if we have one model with some associated objects ...

Overriding Name Conventions for table name and primary key in rails models

Hi friends, Today we are going to talk about overriding the default naming conventions for table name and primary key in rails model. Before switching directly to the topic lets take a look to the summary of default naming conventions for dat...

has_and_belongs_to_many relation in rails

has_and_belongs_to_many association is used in rails where we dont need a third joining model to establish the relation between the two model. There will be no additional columns (except the foreign keys) of the third joining table. For exampl...

EAGER LOADING IN RAILS

In each & every real life scenario our utmost focus is on saving the time. In terms of DB we can save this time by reducing the number of SQL queries fired. This is what Eager Loading is used for. Rails provide us 3 methods to perform Eager...

How to check variable is being passed in partial

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 hash and hashwithindifferent Acess

The Hash class in Rubys core library retrieves values by doing a standard == comparison on the keys. This means that a value stored for a Symbol key (e.g. :my_value) cannot be retrieved using the equivalent String (e.g. my_value). On the other ha...

How to catch phone number in string

While sending internal message on a system people usally share there phone number and making call outside the system which divert traffic from our system. So while exchanging messages within system we need to hide the phone number. This can be ac...

Difference between nil?, empty? and blank?

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...

Activerecord callbacks

Callbacks are methods that get invoked at various stages of an Activerecord objects life cycle. and thus it is possible to write code that will run whenever an Activerecord object is created, saved, updated, deleted, validated, or loaded from th...

How to protect rails application sql injection

There are times when SQL injection is the most shocking attacks on the internet. SQL injection means a condition where user is molding a SQL query in a unexpected form.If the queries are not handled properly it can lead to results like leaking of...

Loading module/class from lib folder in Rails 3

Autoloading of modules/classes from lib directory is no more supported by Rails 3. There has been number of if and buts in its support and against but unfortunately it has been removed. While lazy loading was a very good feature where developer n...

Using Group By in Active Records

To use a GROUP BY clause to the SQL fired by the finder, you can specify the group method on the find query. For example, if you want to find a collection of dates the Orders were created on: Order.select("date(created_at) as ordered_date, ...

Direct sql Queries in Rails

If any of you want raw sql query in rails you have to use the find_by_sql method. This method returns an array of records. For example Post.find_by_sql("SELECT title FROM posts WHERE author = ? AND created > ?", author_id, start_date) w...

attr_accessible in Rails 4

Before going into the details of attr_accessible, the best thing would be to understand why it was needed. It was basically needed to avoid the Mass-assignment Attack. For that we need to know about Mass-assignment :- Mass-assignmen...

Difference between running a rails app in development or production mode

In this blog I am going to discuss difference between rails development and production mode. Often Rails app has so many different environments, each environment use different database which is mentioned in config/database.yml file, each environm...

Getting the current absolute URL in Ruby on Rails

Recently I was working on rails 4 application and there was a need to get current absolute URL. So I noticed that as rails evolved, this is also getting changed and thought to pen down these ways for all the rails versions. For Rails 3.2 or Ra...

Top 5 ruby gems most helpful in application

Devise(https://github.com/plataformatec/devise): It represents authentication mechanism. Very powerful, flexible and also it allows to integrate Outh authentication system with minimal effort. FriendlyId(https://github.com/norman/friendly_id...

Configuring i18N Api in rails internationalization

Rails Internationalization : Configure the i18n Module As we all aware that whenever we use term web, it refers to globalization of application. For globalization, your application must support multi-language support. In ruby i18n provides t...

Verification of credit card on Braintree while making payment

While integrating a payment gateway with our site we seldom come to a case where user already entered credit card information is not able to get verified. Thus a particular amount is being lost by the site owner. There are various resaon f...

Encoding issues while parsing CSV file using Roo gem in rails

This is the most common and frustrating issue while parsing a csv file in rails i.e. the encoding issue. So in ruby on rails i found a library which basically detects the Character encoding using ICU (dependency package) and the name of the libra...

Helpers

Helpers in rails framework are live example of modules of ruby. The methods which are defined in helpers are available to the templates(view) by default. These helpers are called template helpers. Some examples are 1)date_helper.rb has methods li...

Creating PG Backup On Heroku

As we all know that creating a backup of your project is very crucial for any application , not just to recover your application in case of any unseen conditions but also for testing , creating a new server , migration etc. Until recently her...

When to use includes or joins in rails

While working with a large relational database in rails we come to point where we have to access data from a large number of tables in a single query. Well for this rails provide us with two very powerfull active records methods i.e joins and inc...

Managing Rails Versions and Gems- Automatically load required version using RVM

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 With Where Or Having clause in Rails

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...

Active record rails

Earlier when programmer used to build a web application, they required the skills to code in both business logic language and database language. However now, back-end frameworks are using Object-Relational Mapping (ORM). It helps programmer st...

Cross site scripting XSS attacks

XSS is cross-site scripting, with this an attacker can insert malicious script/html into the victim's browser. The end users browser has no way to know whether he script is trusted. It assumes the script came from the trusted source. The malic...

Partials in Rails Application

Partials allow us to easily organize and reuse our view code in a Rails application. Partial file names typically start with an underscore (_) and generally end in the .html.erb extension as our views. The .erb extension may vary depending on tem...

Working with migration in Rails

Rails make use of ORM(Object-Relational Mapping) i.e a layer between your actual database and your model logic in the form of Active Record. As rails provide you with ORM in form of Active Record all the code that you need to write to interact wi...

Updating Ruby on Rails Version

When coding with some framework we seldom come to a stage where we need to upgrade our framework as latest version of it is released. Upgrading your framework to latest version is not often so easy especially if there is a major version update. ...

Basic Caching in Rails

What exactly is caching and how do rails try to achieve it. Well basically rails provide us with an automatic caching feature which help us in increasing the speed of our site by reducing the amount of time consumed by making frequent call to eit...

Rails Initialization Process and Init.rb

Today I am writing a blog about rails initialization process for beginners. Rails initialization process a vast topic. Here I am going through the use of config/environment.rb, config/environments/production.rb, config/environments/staging.rb, co...

JSON and XML

JSON VS XML (RUBY) JSON stands for JavaScript Object Notation. XML stands for EXtensible Markup Language. Both Json and Xml are used for exchanging data. JSON is a light-weight text-based open standard design for human-readable data. It is...

Collect and Map In Ruby On Rails

Map: Map use to take the object of enumerable and returns a new array with the results of running block once for every element in enum, the block is something like [1,2,3].map { |a| a+2 } and the outcome of [1,2,3].map { |a| a+2 } will be [3...

Using Bundler With Rails

Bundler is a default gem manager attached with Rails 3 in order to maintain list of gems being used in the project. Although we are talking about bundler here with respect to rails we can use it independently with Ruby too without any dependency ...

In app notification using pusher app

Now days web application do need to have real time notifications. Most of us does have taken note of it while using application like facebook, twitter etc. There are various ways of achieving it but pusher app has taken all the pain of developer ...

Scraping using nokogiri in rails

We usually want to scrap some data from one site or other . For this rails have provided us with a well known gem Nokogiri . It is a library which has been written for scrapping data and any rails developer can scrap data with the use of followi...

Things to take care while creating API- Some Important Tips

Some Important Tips While Creating an API While creating a web project we do need to create API which can be used by any third party like iPhone,Android etc. Below is a link of an article which can help you in keeping thins in mind while creat...

Some thoughts about a rails CMS

Well all need to work with some kind of CMS which help us to achieve some predefined functionality quickly already provided by the respective CMS. Rails too have moved ahead with it and have created a CMS for it's developer and one of it is : Ref...

Minimum security features which a developer must take of while coding in rails

My last post was on How one should take care of app complexity before refactoring it Below is the list of minimum security features one should take care while making an application using ROR : 14 Bare Minimum Security Checks Before Releasi...

How one should take care of app complexity before refactoring it

All developers who are working on big projects usually think on refactoring the code-base. But before moving ahead with it a developer must take care of the following app complexity How To Score Your Rails App's Complexity Before Refactoring ...

Installing RMagic on Mac Mavericks and Issues explained

Installing RMagic 2.13.1 is generates issues on Mavericks when working with Brew... The problem is that the latest version of ImageMagick on Brew repos conflicts with RMagic version.. So you need to build older versions of ImagicMagick like 6.8...

Default function for Increment/Decrement updates database field values in rails 2.3.8

Generally at the time of development a situation of incrementing or decrementing a database field it can come like Number of views for a particular page or Number of views of a individual profile. In rails there are two default functions for this...

How to Apply Active Record Observer on a Particular Column

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....

Parition of log files

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...

Install pdfkit and wkhtmltopdf library on Ubuntu 12.04/ruby

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...

how to get remaining months between two dates in ruby

Below is the code to get remaining months between two dates date1 = '2011-03-31' date2 = '2011-02-25' (date1.to_date.year * 12 + date1.to_date.month) - (date2.to_date.year * 12 + date2.to_date.month) ...

How to Update Ruby Version

Install ruby to C:\Ruby193 and set RUBY_HOME=C:\Ruby193and %RUBY_HOME%\bin added to PATH sys var., Go to http://rubyinstaller.org/downloads/ Download the devkit: DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe Extract Files by left double-click...

How to create Ruby hash in just one line ?

When we have to create a hash in just one line we can use this particular ruby code: @users = User.find :all user_hash = Hash[@users.map {|x| [x.id, x.name]}] Here we created a hash in just one line with Id as the key of hash a...
1 9
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: