I’m trying to find all Users with an id greater than 200, but I’m having some trouble with the specific syntax. User.where(:id > 200) and User.where("? > 200", :id)...
I need to add timestamps (created_at & updated_at) to an existing table. I tried the following code but it didn’t work. class AddTimestampsToUser < ActiveRecord::Migration def change_table add_timestamps(:users) end...
Suppose I have the following two objects: first_name_relation = User.where(:first_name => 'Tobias') # ActiveRecord::Relation last_name_relation = User.where(:last_name => 'Fünke') # ActiveRecord::Relation is it possible to combine the two relations...
I have a rake task that won’t work unless a table exists. I’m working with more than 20 engineers on a website so I want to make sure they...
How do you do an OR query in Rails 3 ActiveRecord. All the examples I find just have AND queries. Edit: OR method is available since Rails 5. See...
I need to query comments made in one day. The field is part of the standard timestamps, is created_at. The selected date is coming from a date_select. How can...
Is there a rails-way way to validate that an actual record is unique and not just a column? For example, a friendship model / table should not be able...
Please help me in understanding the :source option of has_one/has_many :through association. The Rails API explanation makes very little sense to me. “Specifies the source association name used by...
I have a list of events that I fetch. I’m trying to include every user associated to this event and every profile associated to each user. The Users get...
In Rails, you can find the number of records using both Model.size and Model.count. If you’re dealing with more complex queries is there any advantage to using one method...

