Skip to content Skip to sidebar Skip to footer

Rails Basics

Rails Basics

Secure Your System With Rails Validations

Validations are a really important concept in web development, they help us ensure that the data our users submit is valid. Rails validations provides a really neat way to define validations using declarative syntax. class User < ApplicationRecord validates :name, presence: true end This validation will ensure that the name attribute is present (not…

Read more

How to use ActiveRecord find_by method

The ActiveRecord find_by method is a shorthand method for finding one ActiveRecord object using one of the model's attributes. What is ActiveRecord find_by Used For? The find_by method queries your database for a specific record or records that match certain criteria. How to Use ActiveRecord find_by The basic syntax for using find by is this: Model.find_by(attribute: value) For example,…

Read more

How to use where ActiveRecord method

The where ActiveRecord method is one of the most powerful features this ORM offers. It allows you to express your conditions as simple key-value pairs, making your code more readable & shielded from SQL injection attacks. Here's a quick overview of how to use it: User.where(name: "John") The where method will return an array of matching…

Read more