Questions tagged [rails-models]

a component of the Rails framework that holds the state of an object and is responsible for enforcing business rules and persisting the object.

367 questions
1
vote
1 answer

Rails PostgreSql store multidimensional array

Is it possible to store a multidimensional array in a column. I have tried the following and received the error below coming from creating the records column. migration_file.rb create_table :balance_sheets_details do |t| t.string :headers,…
Cody Elhard
  • 655
  • 1
  • 7
  • 17
1
vote
1 answer

Assign user model to one of two models?

I have a user model that I want to assign to be teacher or student( teacher and student are two separated model ) because if the user signup he would have different registration fields depending on if he is teacher or student. User can be a teacher…
kubet
  • 55
  • 4
1
vote
1 answer

Rails Updating Data in one Model from another Model's Controller

I have a User model that has billing_id. I have Order model that runs transactions with a payment gateway which returns a billing id I'd like to save into the billing_id column on the User model. I think I am getting the basics of MVC architecture…
railslearner
  • 1,761
  • 2
  • 14
  • 18
1
vote
2 answers

query in rails3

In another question that i asked recently i got a really good answer and the code worked... But i do not know exactly why it works... Now i have a similar problem, but don't know how to solve it...? What i have: Models users questions (with…
Thijs
  • 387
  • 5
  • 20
1
vote
2 answers

rails3 model question

i moved from php to rails3, and i still think it was a good decision! Anyway I have some models: users questions answers question_id votes user_id answer_id model for users: has_many :questions has_many :votes model for questions: belongs_to…
1
vote
1 answer

Using models and migrations in code

I try to wrap my head around a problem I try to tackle in a Ruby on Rails application, but after three days of searching and trying, I seem to get tunnel vision and am stuck: I have products and shops and a product can be sold by many shops. The…
1
vote
1 answer

Rails model references question

class CreateMatches < ActiveRecord::Migration def self.up create_table :matches do |t| t.integer :result_home t.integer :result_away t.references :clan, :as => :clan_home t.references :clan, :as => :clan_away …
methyl
  • 3,272
  • 2
  • 25
  • 34
1
vote
2 answers

All table fields are not showing? (Rails/MySQL)

I've created new fields, "first_name", "last_name", "email", and "password" in the model generated migrate file as shown: class CreateUsers < ActiveRecord::Migration[5.2] def up create_table :users do |t| #added fields …
1
vote
1 answer

Trouble creating a new record in Rails with Select Boxes and Foreign Keys

Ruby on Rails newbie here. TL;DR: When trying to create a new record, I get an error message saying my foreign keys must exist. I'm using Select Boxes on my view. Need help. I am creating a requests management system for our own support staff here…
1
vote
1 answer

Scoping f.collection_select

I've got a model that I'm using a collection_select on and I'd like to scope it to show only accounts that are open. To accomplish this, I've added a boolean field to my account model, defaulting to false. Here's my attempt at that in my account…
1
vote
1 answer

Rails - How to load nested attributes by condition while loading parent?

I have two models namely Invoice and InvoiceDetails. An invoice has many invoiceDetails. Now when I load an invoice, it also loads up the invoiceDetails attributes by association. The invoiceDetails model has an attribute is_hide, I want to load…
Paras
  • 3,191
  • 6
  • 41
  • 77
1
vote
1 answer

Update record by conditions Ruby on Rails

Can we update a record by conditions without check the record first?
Aditya Hadi
  • 364
  • 1
  • 4
  • 17
1
vote
4 answers

How should these Rails Models be associated?

I have over thought this to the point that I'm only getting confused now. I have a Rails app with the following as models: User, Site, Tutorial, TutorialStep. A user can create many tutorials and each tutorial has a site it lives on, and each…
stevenpslade
  • 310
  • 1
  • 18
1
vote
2 answers

Highest rating comment in rails

I'm trying to show the comment with the highest rating in the product show page but it shows # instead of the comment. Any ideas why? #comment model class Comment < ApplicationRecord belongs_to :user belongs_to :product scope :rating_desc, -> {…
BoB
  • 133
  • 1
  • 11
1
vote
1 answer

rails_admin: changed relationship, form not correct

I have a relationship between compositions and languages. One composition should be written in one and only one language. My schema.rb contains the following lines: ... create_table "compositions", force: :cascade do |t| ... t.integer …
Simon
  • 701
  • 6
  • 25