Rails API mode was introduced in Rails 5 as a way to create APIs that don't require session state or cookies. It's a lightweight mode that comes with a few features that are specifically geared towards API development, such as:
No need to generate views.
Only include the gems that are needed for API…
If you want to connect PostgreSQL In Rails, you first need to install the pg gem. You can do this by adding the following line to your Gemfile:
gem 'pg'
Then run bundle install from the command line to install the gem.
Once the gem is installed, you can require it in your project.
Example:
require "pg"
The pg gem defines…
In this article, we'll show you how to use Paperclip in Rails to add images processing them.
Paperclip is a gem used for image processing in Ruby. It is one of the most popular image processing gems and has been used by projects like GitHub, Shutterstock, and thoughtbot.
How to install Paperclip
To install Paperclip, add it…
There are a lot of built-in methods for working with arrays in Ruby. Most of the time, you will find a method that does exactly what you need.
In this article, we will go over some of the most popular array methods that you can use in your ruby code.
Finding the Length of an Array
If…
This tutorial will show you how to use GraphQL in Rails.
GraphQL is a language for querying data that was created by Facebook. GraphQL is often described as a "better REST" because it allows you to query for exactly the data you need instead of getting more data than you need, like with a REST API.
If…
The following post will show you how to implement Capybara in Rails to simulate user interactions.
Capybara is a ruby gem for writing integration and system tests. System tests are basically testing that click around your web application to check if all the functionality is working as expected.
Using Capybara, you can:
Crawl your application (like a…
Docker is a great tool for developers; it provides an easy way to create and manage containers. You can implement Docker in Rails with this tutorial.
If you are unfamiliar with containers, think of it as a way to isolate your application from the rest of the system. This way, you can run multiple applications on…
Rails associations are a way to link one model to another. There are four different types of associations:
One-to-one
One-to-many
Many-to-many
Polymorphic
Each type of association has its own set of methods that you can use to interact with the associated data.
One-to-One Associations
A one-to-one association means that each record in one…
The Roo gem makes it easy to work with Microsoft Excel (xls and xlsx) files in your Ruby project.
You can add it to your Gemfile with:
gem "roo"
Once you have installed the gem, you can create a new instance of the Roo::Excelx class:
require "roo"
xlsx = Roo::Excelx.new("path/to/file.xlsx")
You can then use various methods to read and manipulate the…
To implement a cache in Rails, you can use the ActiveSupport::Cache class.
The ActiveSupport::Cache class provides a unified API for a variety of caching backends.
For example:
Memory store
File store
Dalli store
You can use the ActiveSupport::Cache::Store#fetch method to read from the cache.
If the data is not in the cache, the block you pass…