All Questions
Tagged with ruby activerecord
8,533
questions
0
votes
2
answers
74
views
How can I update how ActiveRecord::Base#where interprets ranges?
It appears that ActiveRecord::Base#where partially distinguishes between ranges defined with 2 dots (0..) and ranges defined with 3 dots (0...).
E.g.
> User.where(id: ..0).to_sql
=> "SELECT ...
1
vote
1
answer
64
views
How to automatically derive foreign key column names with polymorphic associations?
In my Ruby on Rails 7 application I have a large Account model with various has_many associations (most of them are left out for brevity here):
class Account < ApplicationRecord
has_one :...
0
votes
2
answers
80
views
Model VS Active record in ROR
Can somebody please explain me the difference between model and active record in simple words ?
Is active model and model same ?
PS: Knowledge regarding these topics will be appreciated.
I am newbie ...
1
vote
1
answer
84
views
ActiveRecord::NotNullViolation: RuntimeError: NOT NULL constraint failed: drives.created_at
I am using latest ruby 3.3.3 and latest rails 7.1.3.4.
I am new to rails and I am learning it. Sorry if my request seems dumb to some.
I got this error when I run tests.
It seems that ActiveRecord is ...
0
votes
1
answer
66
views
Can't find the cause of a has many through association error
I'm building a token provisioning API that enforces quotas. When I try to create a Token, I keep getting the following error, and I cannot figure out why:
ActiveRecord::...
1
vote
2
answers
61
views
saved_changes is empty after persisting changes on a Rails model
We have a Rails 6.1 application running an after_commit callback to look into saved_changes value to run some background workers. But the issue is saved_changes returns empty if a model has ...
0
votes
1
answer
55
views
How the correct way to implement a functionality
Guys, I have a doubt about the correct way to implement code with rails.
I have a functionality that saves some sales data from some operators who currently view them from spreadsheets.
(nsu, value, ...
-1
votes
2
answers
97
views
How to include or not include Rails module based on condition? [closed]
In my Ruby on Rails app I have this model:
class Car < ApplicationRecord
attr_accessor :name, :brand, :origin_country
module ShippingCostCalculatorForJapan
def calculate
# Details ...
1
vote
1
answer
56
views
Rails - How to Create Association to 2 Sub-classes Part of SIngle Table Inheritance
So I have set up Single Table Inheritance so I can create two sub-classes for the User table. In my current implementation, both subclasses will have the exact same fields so STI makes sense here I ...
1
vote
1
answer
64
views
Rails Exception No Such Table Exists
I used rails generate to scaffold a ProjectType table and a ProjectGroup table that references project type. I created a project type successfully through the browser, but when trying to create the ...
1
vote
1
answer
45
views
How do I handle associations in Ruby on Rails when the JOINS involve more than 2 tables?
I'm working on a Ruby on Rails server (v6.0.1) and I'm looking for cleaner ActiveRecord joins when the join involves three tables. Here's a barebones reproduction of five models under consideration to ...
1
vote
0
answers
70
views
how can we use model object method in rails select query
I have two models, first one is User with attributes first_name, last_name and second one is Organization with attribute partner_level which is enum {standard: 'standard',standard_plus: 'standard_plus'...
1
vote
1
answer
168
views
Rails 7 ActiveRecord::SessionStore - how to get database id of current session in the controller?
I'm using Rails 7.1.3.2 and have just installed activerecord-session_store (2.1.0).
https://github.com/rails/activerecord-session_store
It's all working - session values i set in the controller get ...
2
votes
1
answer
97
views
Pattern matching an array of n items
I'm testing a model in rails, and I'd like to assert that one of the associations has an n items. I've found that the assert_pattern matcher is a pretty good way to do it:
assert_pattern do
author....
0
votes
1
answer
89
views
Rails Active Record Statement Invalid Undefined column
I'm completely new in using ruby on rails and active record.
I cant seem to figure out why I keep getting this error. I am trying to delete soccer teams through the destroy method and it wont work. ...