367 questions
0
votes
0
answers
93
views
Rails Admin field filter in a has_one through relationship
I have a Remediation model which inherits from AssessmentHighRiskFactor model and added some custom show fields from other tables using relationships. The fields are visible and working fine, but I ...
1
vote
0
answers
286
views
Paper trail not writing destroy events for join table soft deletes
I'm using paper trail in my app partially to display an audit log of changes and have noticed that it won't track destroy events when items in join tables are soft deleted (it works fine for other ...
0
votes
2
answers
67
views
Passing a variable in an after_update action
I have an UserProfile model:
class UserProfile < ApplicationRecord
after_update :check_changes
def check_changes
AuditRecord.create(account_id: self.id, fields: self.saved_changes , ...
1
vote
0
answers
97
views
How to decide for Single Table Inheritance in Rails and use multiple models in a unified view?
Let's say you run a content site for cartoon artists. Cartoon artists create a lot of resources: Drawings, Articles, Magazines, Books, Schemas, Projects, Courses, Lectures etc. Those resources have ...
0
votes
0
answers
127
views
Rails Associations - has_one, belongs_to_many
It's been a while since I've worked with Rails (Rails 6) on a new application. I'm failing to recall how to properly set up associations. I have two problems that are rather similar and may help to ...
0
votes
1
answer
330
views
Can't mount newly generated Rails engine in an app
I have a complex Rails app and I want to extract some core functionality into an engine so that I can reuse the models etc in other Rails apps.
I've been following the official documentation for ...
-1
votes
1
answer
801
views
How can i write a method that can generate scope dynamically which can be used for multiple models in ruby on rails
Currently, the existing scopes are like this.
module TransactionScopes
extend ActiveSupport::Concern
included do
scope :status, ->(status) { where status: status }
scope ...
1
vote
2
answers
245
views
i18n-tasks custom scanner for enums
I would like to create a custom scanner for i18n-tasks that can detect enums declared as hashes in models.
My enum declaration pattern will always be like this:
class Conversation < ActiveRecord::...
0
votes
0
answers
258
views
How to avoid saving nil/blank in accepts_nested_attributes_for when displaying set number of fields for has_many association?
My question is an edgecase of how to avoid saving empty records on a nested rails form. I have a simple has_many, where a user can have a maximum of 5 job titles.
# user.rb
has_many :job_titles
...
0
votes
1
answer
334
views
How to retrieve associated records through more than one other table?
Here's a simple setup where the user will always be a patient, and the user may or may not also be a physician:
# user.rb
has_one :physician
has_one :patient
# physician.rb
belongs_to :user
...
0
votes
2
answers
346
views
How to find out all the association of a model?
Say I have following models
class User < ApplicationRecord
devise :database_authenticable,:registerable
:recoverable, :trackable, :validatable, :rememberable
belongs_to :loginable, ...
0
votes
2
answers
42
views
Rails Associations (many to many)
I'm working with Ruby on Rails ActiveRecord and trying to realize my database structure.
What I want is something link this:
User
id
username
License
id
name
ActiveLicenses
user_id (foreign key to ...
0
votes
0
answers
136
views
What are the consequences of too many unnecessary associations in rails database?
Sometimes it feels natural or is at least tempting to make model associations based on columns that can be associated. But that doesn't mean they should be associated.
What price does a database/app ...
-1
votes
1
answer
331
views
Rails model default value being ignored when new record created?
I have a Message model like so
class CreateMessages < ActiveRecord::Migration[6.0]
def change
create_table :messages do |t|
t.text :body
t.references :conversation, null: false, ...
0
votes
1
answer
410
views
Add additional attribute on a has_many through in Rails
I have set up the following associations:
class BookLaunch < ApplicationRecord
has_many :book_launch_locations, dependent: :destroy
has_many :stores, through: :book_launch_locations
....
...