a component of the Rails framework that holds the state of an object and is responsible for enforcing business rules and persisting the object.
Questions tagged [rails-models]
367 questions
-1
votes
1 answer
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 :portfolio_id, ->(portfolio_id) { where…

Ramachandra Hegde
- 45
- 8
-1
votes
1 answer
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, foreign_key: true
t.references :user, null:…

stevec
- 41,291
- 27
- 223
- 311
-1
votes
1 answer
Student Batch Grade Relationship Rails
A student gets admitted to a school and in its admission form, I want the user to assign student his/her batch and grade as well. Batch has many grades and grade belongs to batch.
In this scenario, I've to create a student form where I need the user…

Talha Meh
- 487
- 7
- 20
-1
votes
1 answer
ERROR in downloading paperclip attachment
I have a model named VehiclePhotos and it has attachment field 'photo'. I used paperclip gem for uploading photos. Uploading was fine without any error. but when I tried to download the image, it gives
'500 Internal Server Error'.
log does not…

jithya
- 428
- 4
- 13
-1
votes
1 answer
Rails nested models and virtual attribute initialization
I have a problem understanding how are attributes "sent" to nested model(s), and if is possible to do this for model with virtual attrubute too. I have three models:
class User < ActiveRecord::Base
...
has_and_belongs_to_many :clearancegoods
…

Kovo
- 434
- 4
- 14
-1
votes
1 answer
Validate price range overlap
I'm working on an application where I'm entering multiple price ranges. I want to validate the price range to keep it from overlapping with another price range. I know how to check whether two arrays overlaps or not, e.g.,
a = [1.0, 2.0]
b = [2.0,…

Rajdeep Singh
- 17,621
- 6
- 53
- 78
-3
votes
1 answer
relationship between students, teacher , periods and attenance
i have User model and (teacher, student and principle) inherit from it using STI
every class has many students and one teacher only.
every student has many classes.
every class has many student
class Class < ApplicationRecord
…

Eslam Tahoon
- 2,205
- 4
- 15
- 21