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

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

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

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

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

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

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

Strict Validator in Rails Model

Hi friends, We already talked about different kinds of validations. Today lets discuss one of the common type of validation that is Strict validation. By using this we can check whether an object is valid or not and can raise ActiveModel::Strict...

Numeric Validator in Rails

Hi Friends, Thanks for viewing my previous blogs, hope you liked them. As we were previously talking about validations starting with Format validations in Rails, lets continue with that with a new validation helper numericality. As its name rep...

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

Format Validators in Rails

Hi Friends, Hope you are doing well with your work. Today I am here with one of the most common topics in Rails that is format validators in rails. Lets start with defining validation. "Validations are used to avoid the invalid data to get sto...

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

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

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