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

Form Helpers in Rails Part-3 (Customization and Forms for External Resources)

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

Use of Render option in Ruby on Rails

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

Form Helpers in Rails Part-2 (Model Objects)

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

Form Helpers in Rails Part 1 (Basics)

Hi Friends, In my previous blogs, I have talked about so many topics related to Ruby on Rails. Now today I am going to start form helpers in rails. As all the points can't be covered in one blog, I am dividing it into parts. Today I will be deal...

Applying partials to layouts in rails

In Rails we can use partials to organize our code in the layouts . This is generally helpful when we have layouts running up to hundreds of lines. For example we have a top nav bar which looks different for logged in and non logged in user. Then ...

Use of :as in Passing parameters to rails partials

While passing objects to partial we can change the name of the local variable in the partial and for that purpose we need to use the :as option. For example we have a partial _account.html.erb where we need to pass a collection @cutomers a...

Capturing part of template in variable in RoR

Hi Friends, Sometimes you need to use a small part of a template at so many places and you have to write the same lines of code on separate places and you also don't want to create separate partials for that. Rails gives a solution to your probl...

Number Formatting in RoR Views

Number Formatting in Rails Numbers are of different formats, according to their uses like phone numbers, percentage, currency etc. In Rails NumberHelper fulfills this requirement by providing methods for formatting numbers into different forms. ...

Passing parameters to rails partials

While rendering a partial if we want to send parameters to the partial we can do it like this: <%= render :partial => user_profile_list, :locals => { :user => @user } %> or <%= render :partial => "user_profile_list", :...

Benchmark helper in rails

Rails has benchmark helper to quickly test the time of execution of a given piece of code. Active Record, Action Controller and Action View libraries provides a benchmark() method to measure the performance of code. Example: Model(Active Rec...

Atom Feeds in Rails

Hi friends, We have recently talked about auto_discovery_link_tag, that consumes RSS and Atom feeds. Now we are going into deep what is the atom feeds in Rails and how we can achieve that. Lets begin with a defining Atom Feeds. Atom Feeds are ...

auto_discovery_link_tag in rails

Hi guys, Today we are going to discuss about auto_discovery_link_tag in rails. It comes under AssetTagHelper, which gives methods for generating HTML that links views to assets(i.e images, JavaScripts, stylesheets, and feeds). For consuming RS...

Builder templates in ROR and its uses

Action view templates can be written in various ways depending on the format of the response. If the response is in html format then we can use .erb files i.e. html files, with embedded ruby in it. If the format is in xml then we need to use fil...

Introspection using ActiveModel

ActiveModel is a library which contains various modules which when added to a class add some features present on Active Record to the class. One such module is ActiveModel::Naming module. This module is used for model name introspection .Below ...

Dirty methods in Rails model

Sometimes we face a situation where after changing the value of an attribute of an object we need the previous or the unchanged value for some purpose. We generally store the previous value in a variable to be used later. Instead of this approach...

Rails Model Translation

Rails Model Translation Translation in Rails active records is used to provide integration between object and the Rails internationalization (i18n) framework. Rails does this using ActiveModel::Translation.Example: class Blog   ext...

Rails model Serialization

Rails model Serialization Hi Friends, Earlier we have discussed about Association in Rails Model. Today we will be covering one more topic related to rails active records, that is Serialization. In summary we can define serialized objects as, S...

Join in rails model

In rails if we want to establish inner join relationship between two models we can do it using joins method of activerecord. For example, consider the following Company, Product, Review and Vote models: class Company < ActiveRecord::Base...

Associations in Rails Model

Associations in Rails Associations are an important part of each Active Records. It makes coding easier and relations clean. Lets take an example of Blog. A Blog can have many comments. So if you delete blog its associated comments also needs ...

Reorder in Rails

Hi friends, Today we are going to discuss about reorder in rails. This method is used to override the scope of order and reorder the rows according to the passed arguments. Example: Blog.order('title DESC').reorder('published_at') # generate...

Having Clause in Rails

Hi Friends, Previously we discussed about Group By Clause in Rails, Now today lets discuss a related clause of SQL, which is Having. SQL uses having for specifying conditions on GROUP BY clause. Suppose we want to fetch the total views of blogs ...

GROUP BY clause in Rails

Hi Friends, As you know GROUP BY is used to group the result-set by one or more columns. The SQL query to fetch the total views of blogs created at same day will be: SELECT date(created_at) as creation_date, sum(view) as total_views FROM blo...

Self Join in Rails

In Self join association one model has relation with itself. For example one user table can have list of all coach and player. One coach can train many players. We will represent the association as: class User < ActiveRecord::Base has_m...

Fetching records in batches in rails

Hi Friends, Many times we get into a situation where we have to fetch a large record from a table and need to iterate over it and that makes our server cry. As it consumes a lots a memory and time. So no need to worry again for that Rails has a...

Polymorphic association

Polymorphic association is little tricky to understand among all the rails association. Using this association one model can have belongs_to association with more than one model in a single line of association. As for example in a social networki...

Fetching Records in Rails using take

take in Rails:Rails has so many methods that provide the facility to fetching the records from database, so that you don't need to write raw sql. One of them is take. By using take we can fetch a record (or N number of records if specified as a ...

find_by in Rails

Hi Friends, Rails provides several methods for fetching single object from table, one of the method is find_by. It fetches the first record in the table matching some specific conditions. Example can be if we want to fetch the first blog with ti...

Choosing Between has_many :through and has_and_belongs_to_many

In Rails we can establish many to many relationship between two models in two ways 1) by using has_and_belongs_to_many 2) by using has_many :through associations. We generally use HABTM when we dont require a third intervening model to join t...

Unique Validators in Rails

Hi Friends, Today we will be going to discuss a very basic constraint of rails validation that is uniqueness, as its name suggests, Unique Validator is a rails validation helper used to check an attribute value in database and if it already exis...

Length Validators in Rails

Hi Guys, In my previous blog Format validators in rails, I talked about validations in rails and now I am here again with one of the most commonly used helper available in rails, that is length. Length validator is used to validate the length ...

Choosing Between belongs_to and has_one

If we have has_one relation between two models then we need to declare belongs_to relation in one model and has_one relation in another model. belongs_to will be declared in the model where we will have the foreign_key and has_one in the other mo...

Virtual attributes in Rails like acceptance and confirmation

Hi Friends, We have talked about few Rails topics earlier like validates associated and overriding naming convention of table names. Here I am again with one more topic Virtual Attributes in Rails. Before discussing that lets look into a situati...

Pessimistic locking in ruby on rails

In pessimistic locking a particular row in the database is exclusively locked so that other updates on the same record are blocked . This mechanism has the advantage that when a certain operation is going on the selected row other user cannot rea...

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

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

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

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

Is Go a solid choice over Ruby on Rails or Django?

GoLang referred as Go programming language developed at Google in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson. It is a statically-typed language with syntax loosely derived from that of C, adding garbage collection, type safety, some dy...

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

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

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

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