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

Questions and Answers App Not Working in Ruby on Rails

I have created a ruby question answer app but on answering the correct answer the question is getting repeated i.e next question is not appearing.

How to isolate cookie store for one subdomain from other subdomains and domain itself in Rails 5?

Hello, I need to have cookie store #1 on a.example.com and I need to have cookie store #2 on b.example.com and on example.com One method was to change cookie name per subdomain / domain, however  request.env['rack.session.opti...

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

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

HAML in Rails

Rails default templating language is ERB which embeds ruby code into a HTML document, but there is an alternative templating language available called HAML. HAML(HTML abstraction  markup language) provides an elegant syntax which is easy to...

find_all method in ruby.

The find_all method has to do with arrays in Ruby.This method simply iterates through all the elements in an array and meanwhile test each of them against a test condition and finally returns an array containing all elements for which the test re...

Rails Command Line Tools

Rails is a language particularly known for its rapid development and shortcut commands that make development of applications and its modules fast and easy. Today I am going to tell you about few most basic commands of rails: 1. rails new: ...

Adding social icons in your site

Hi friends, You might have seen several icons of social networks in many of the sites. If you want to add this in  your rails site, there is already a beautiful gem called social-share-button. I am explaining here how you can integrate it s...

Pagination in Rails Using will_paginate Gem

Hi Friends, Today I am going to tell you how we can integrate pagination in rails. First let's know why pagination is required in an application. Pagination is fetching data in batches and rendering one batch  at a time. It is nece...

variables in ruby

Variables in ruby Variables are used to hold any data which will be later used by programs. There are 5 types of variables in ruby 1.Ruby global variables 2.Ruby instance variables 3.Ruby class varibles 4.Ruby local variable 5.Ruby...

Rspec PART 1 - Introduction

Introduction to Testing: The question that always arises is that why we should test a software/code? can't developers code  like we need not to write test cases for it to ensure its correctness and quality. The answer to above ques...

implement thumbnail image in image uploader

how to implement thumbnail for image in rails. step 1:- go to uploader inside views where you have written image uploader code for uploading image. uncomment this section #Create different versions of your uploaded files: ve...

Use of seeds in Rails

Hi Friends, Few days back I was facing an issue that once I was creating an application in development mode, I needed to sign up to my application with fake emails, so that was very troublesome process, so I found out about seeds in rails. ...

views in ruby

Hello friends, I hope you all are doing well, so today I would be discussing rails view in ruby in rails. View in ruby is used to display the data which is requested by controller from web with the help of shareable variables. We usually end view...

Important Methods of Date in Ruby

We often stuck, how to manipulate Date in our rails Application.   We have two Date objects in Ruby Time.now() // This will give Today's date #=> 2016-05-17 17:02:28 +0530 Date.new() // This will need some arguments to pa...

Service Objects in Rails (Refactoring)

"Fat models, skinny controllers" has been the design style for Rails app development. However, with time this style has been outdated as with code growth the models become too fat to handle. Why not use concerns? ActiveSupport c...

routes and resources in ruby

If you are new to ruby then you must have wondered about what is routes in ruby, so today I will discuss everything about routes in detail. Rail routes are used to dispatch URl to the controllers action. it is used to generate path for particular...

Iterators in Ruby

Iterators are used to iterate over each element of a collection or array one by one. In ruby there are different types of iterators. Here we are going to discuss over each and collect. 1. each: It iterates over each element of the array or ...

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

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

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

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

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

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

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

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

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

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

Transaction in Rails

To maintain the data integrity sometimes we need the changes to database to occur when all of the actions have successfully finished.  One of the examples is funds transfer from one account to another. One account should be debited and anoth...

Rails Environment Configuration Variables

While developing Rails application we need to keep our project specific sensitive information secure. For example api keys for third parties like stripe, paypal or passwords or configuration data such as the URL. We can set these as environment...

Block, Proc and Lambda

Blocks, Procs, and Lambdas Hi friends, Today I am going to explain one of the most confusing part in Ruby, that is Block, Procs and Lambdas. It always troubles you during interviews or any other places wherever you deal with Ruby. But actua...

Integrating payment gateway in Rails - Part 1

Payment gateways are used in websites for online shopping and money transactions. It safely handles customer payments. Payment gateway can easily be integrated in Rails application. Few applications for payment gateway integration in Rails are Sr...

Rails 5 features

Rails 5 is soon going to release. Many New features have been introduced in this major release. We will discuss the improvements and features here. 1. A few improvements have been made in Turbolinks. Tubrolinks allows us to reload require...

Rating Gem in Ruby on Rails

How to setup a rating feature in rails application.   The best and simple way of doing so is by using RAILS GEM ratyrate by following simple steps.   Step 1: Include GEM in your gem file gem 'ratyrate'   Step...

Setup redis with ruby on rails

Installing Redis curl -O http://redis.googlecode.com/files/redis-2.2.2.tar.gz tar xzf redis-2.2.2.tar.gz cd redis-2.2.2 make cp src/redis-server src/redis-cli /usr/bin Redis Server If you want to use redis-server locally,  j...

Background job using whenever gem rails

Whenever gem is used to easily schedule tasks using cron jobs, it enables you to manipulate standard functionality of your machine using Ruby code. 1: To start with Whenever we have to install gem gem install whenever # insert this li...

difference between HAS_ONE and BELONGS_TO association in rails?

Has_one and Belongs_to relationship sometime become confusing so the main difference can be explained with the help of example: 1>Has_one :- class Department < ActiveRecord::Base has_one: employee end this means that employee tab...

how to do adpater settings in rails for postgresql database ?

There are few steps for doing adapter settings: 1> inside your app go to app_name/config/locales/database.yml default: &default adapter: postgresql pool: 5 timeout: 5000 username: postgres password: 123456 developme...

How to create a new column in an existing table in Rails

This the existing table in migration folder. class CreateArticles < ActiveRecord::Migration def change create_table :articles do |t| t.string :title t.text :text t.timestamps null: false end end end ...

Single Table Inheritance in Rails

STI can be considered where single table can be used to represent multiple models based on different type. The parent model inherits from ActiveRecord::Base. Other models inherit from parent model. Data store and accessed from same table for all ...

Using rescue in single line

We can use rescue in single line to return a value if code of that line raise an error/exception, example shown below-: Let say we have a hash: person = {:name => "ABC"} person[:name].downcase # "abc" ...

Converting timezone of date-time without effecting the actual time

I am looking for a way in rails using which I can change the timezone i.e UTC or GMT of date time string without actually making any changes to the original string (just want to change the timezone) . Is there any inbuilt time method in Rails...

Celluloid::Task::TerminatedError for sidekiq

We have few workers working in the background and there has been as error being recorded in the rails error log i.e "Celluloid::Task::TerminatedError from Sidetiq::Clock#loop!". I am looking for a solution regarding the same but has been un...

Using session objects in Ruby on Rails

Session objects are used in ROR to store small amount of information which can be used later on. In fact websites following http (a stateless protocol) use session object to keep logged in user informations so that those informations persists b...

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