I want to return a list of records whose created_at more than 5 seconds before its updated_at i.e. But this syntax doesn’t appear to work. Getting the error: Answer You didn’t say what database you are using, but with MySQL you can the TIMEDIFF function for this: If you are using Postgres:
Tag: ruby-on-rails
Writing a Rails migration to collapse booleans into an enum
I made a mistake when modeling my data and created a model with 4 booleans, only one of which are active at a time. I want to create a column of Postgres enum type, and then set the value based on …
Rails 5 where or active record query
I’m trying to write a query that counts the number of products from a supplier group that are on a specific state or return 0 if it doesn’t have products. This query will only return the count if the …
Populate an HTML DropDown List with data from mysql database without PHP
I’m currently building a rails app where im trying to fetch data from different tables from my sql database and I need to put that fetched data (id, first_name, last_name) into an HTML Drop-down where …
Ruby on Rails iterate through column efficiently
created_at iteration group_hits_per_iteration ——————————————————————– 2019-11-08 08:14:05.170492 300 34 2019-…
Locating unique column values and use the output for the next query
Rails 6.0.0 ruby-2.6.2 Hello I have a model called “Group” which connects to an SQLite database. This database has two columns I’m interested in, they are hits, as an integer and iteration as an …
operator does not exist: timestamp without time zone ~~* unknown ruby code
I am try to query users in the database when I do a search. However i am getting a specific error which is ‘operator does not exist: timestamp without time zone ~~* unknown’ In my database, the …
How to write a query to compare current date to created_at timestamps in database?
I would like to write a query to compare created_at timestamp with my current date in Ruby on Rails using ActiveRecord and I don’t quite know how do it yet Date is stored like this -> created_at: …
Get relation of a collection in rails
So simple but can’t find how to do it in rails. I have a specific active record collection of users. Something like users = User.where(blabla). Given this collection is there a simple way to get all …
rails multiple has_many relationships between the same models
I’m trying to figure out the best way to model a many-to-one relationship in rails where there are multiple scopes to the relationship. An example would be a restaurant has-many photos. I want to be …