I came across a guy with two dots in Rails

Was it in the curriculum?

When I first saw it, I thought it was a mistake in the description. When I asked the mentor, I hadn't seen it at first. I was told! I looked it up and learned that this is an object.

Below is the code in question.


date: @todays_date..@todays_date + 6)

This is a 2-point dot, but there are also 3-point dots.

It's called ** range object **. It seems to be used when saving to SQL ・ Low code and high readability ・ Less likely to cause an error It seems to have the above merits.

How to use it?

rails


User.where(age: ...30)

The above code

SQL


SELECT "users".* FROM "users" WHERE "users"."age" < 30

Certainly it will be shorter.

The code at the beginning is called ** Between **. Simply put, it feels like the value on the left to the value on the right!

I referred to the following page. If you are interested, please take a look!

[Rails] How to write ActiveRecord where comparison and range search code using range object (Range) https://simple-minds-think-alike.hatenablog.com/entry/active-record-where-with-range

Recommended Posts

I came across a guy with two dots in Rails
I made a LINE bot with Rails + heroku
I made a portfolio with Ruby On Rails
[Rails / JavaScript / Ajax] I tried to create a like function in two ways.
I want to use a little icon in Rails
[How to insert a video in haml with Rails]
I want to define a function in Rails Console
I made a development environment with rails6 + docker + postgreSQL + Materialize.
[Rails] I tried to create a mini app with FullCalendar
Japaneseize using i18n with Rails
I searched for a web framework with Gem in Ruby
A story I was addicted to in Rails validation settings
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
A note of what I stumbled upon and noticed in catching up with Laravel from Rails
[Rails] I made a simple calendar mini app with customized specifications.
Do I need a test if I do DDD in a language with types?
I want to add a browsing function with ruby on rails
I can't create a Java class with a specific name in IntelliJ
I got a warning message with the rails _6.0.3_ new hello_myapp command
How to rename a model with foreign key constraints in Rails
I tried to make a group function (bulletin board) with Rails
Add a search function in Rails.
I created a PDF in Java.
I made a GUI with Swing
Create a new app in Rails
Implement a contact form in Rails
I built a rails environment with docker and mysql, but I got stuck
[Rails] I want to send data of different models in a form
The parameters I received in Rails were a bit different than I expected
I want to select multiple items with a custom layout in Dialog
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (PowerMockito edition)
I tried to build a Firebase application development environment with Docker in 2020
I wanted to implement a slide show in a fashionable way with slick.
I wrote a Lambda function in Java and deployed it with SAM
Build a bulletin board API with authentication authorization in Rails # 13 Add authentication header
I want to ForEach an array with a Lambda expression in Java
I tried a calendar problem in Ruby
[Rails6] Create a new app with Rails [Beginner]
How to insert a video in Rails
[Rails withdrawal] Create a simple withdrawal function with rails
I tried playing with BottomNavigationView a little ①
I made a risky die with Ruby
Make a login function with Rails anyway
Steps to set a favicon in Rails
I made a rock-paper-scissors app with kotlin
[Rails 5] Create a new app with Rails [Beginner]
Split a string with ". (Dot)" in Java
Make a site template easily with Rails
Configure a multi-project with subdirectories in Gradle
I made a rock-paper-scissors app with android
I tried embedding a formula in Javadoc
Build a bulletin board API with authentication authorization in Rails 6 # 5 controller, routes implementation
Introduced # 10 devise_token_auth to build a bulletin board API with authentication authorization in Rails 6
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (Javassist second decoction)
Introducing # 15 pundit to build a bulletin board API with authentication authorization in Rails 6
How to store data simultaneously in a model associated with a nested form (Rails 6.0.0)
Rails6 I want to make an array of values with a check box
Build a bulletin board API with authentication authorization in Rails # 17 Add administrator privileges
SpringSecurity I was addicted to trying to log in with a hashed password (solved)
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (black magic edition)