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

How do I model a table tennis match in rails

I am attempting to model a table tennis match in rails. Here is what I have: Game Model: team_1_score team_2_score team_1_id team_2_id Team Model: game_id player_id Player Model: Name So each game will consist of 2 teams (of either 1 or 2 players…
thargor
  • 453
  • 3
  • 11
1
vote
1 answer

Rails relationship between three models confusing

I know there is a plenty of tutorials explaining how to create a 'has_many through' relationship between models, but I think my question is both technical and conceptual. The objective is to create an online food ordering website I created the…
Bruno Farias
  • 785
  • 8
  • 22
1
vote
0 answers

How to count unvoted Options powered by "thumbs_up" gem WITHOUT RETURNING AN ARRAY

Poll has_many Questions, Question has_many Options, Option acts_as_voter I tried to count unvoted options BY SQL, WITHOUT RETURNING AN ARRAY this work [22] pry(main)> unvoted = Option.tally.where('question_id = ?', 3).having('COUNT(votes.id) = 0') …
srghma
  • 4,770
  • 2
  • 38
  • 54
1
vote
1 answer

How do I get a Rails association to use a certain name to access a model of a different name?

Let's say I have a user model and a movie model as well as tables to store them. Let's say I want to add a watchlist feature by adding a third table called watchlist_movies that simply maps a user_id to a movie_id. I now want to add a…
1
vote
2 answers

Rails - How to call values from one model into another model form

I'm working on some app and I have 2 models. Categories in which I create category names and Question. Category has_many questions and Question belongs_to Category. I've added category_id to Question model. Now I need to take all Category_names…
RubyDigger19
  • 835
  • 13
  • 38
1
vote
2 answers

Mutual relationships in rails 4

I'm trying to allow users in my app to be mutual friends with one another via friend requests and I'm a little confused with the how the relationships work... When a friendship is created by one user and accepted by the other, I would like the…
Riptyde4
  • 5,134
  • 8
  • 30
  • 57
1
vote
1 answer

Rails 4 Duplicating Model Objects and Merging New Object attribtues (Amoeba Gem)

What I'm doing: Duplicating a record of my Project model then overwriting the modified attributes from an object submitted by a form. The new record should be modified but have all the associations as the original. The first step I took was to…
1
vote
1 answer

Rails. Multiple instances of same foreign key in a single table

I'm not sure how to model the following requirements: We send packs of 3 different beers to our users. The users are divided in 4 categories of tasting_profiles. Then, we prepare 4 different packs of beers for all our users. Then the users rate the…
Lastimoso
  • 218
  • 3
  • 11
1
vote
1 answer

Rails - four tables associations -

a rails newbie here, looking at doing some work with 4 tables and not totally sure how to structure the associations. Below topic involves real estate, probably helpful to keep that in mind. I have four models: Property - a physical house Project…
1
vote
2 answers

Relationships in Ruby on Rails: what is the proper model building method for a list?

I'm trying to figure out what is the proper way to setup my model and database if I have a list under itineraries... Database Table `users` id `itinerary` id user_id items Model class User < ActiveRecord::Base has_many :itineraries end class…
hellomello
  • 8,219
  • 39
  • 151
  • 297
1
vote
0 answers

touch should not updated `updated_at` on destroy in Rails3

I am working on touch in Rails but facing on issue here. class User < ActiveRecord::Base belongs_to :company, touch: true end But I want this should not update the updated_at of company model only when I delete the user but other case it should…
Vinay
  • 324
  • 1
  • 3
  • 15
1
vote
1 answer

A Very Specific ActiveRecord Validation

I'm will try to explain my dilemma as best I can. I have a 2 models Users and Devices Devices has a type column. For example it can be a Tablet or a Smart Phone. I then have another model Ownership This model belongs to both Users and Devices so…
Dan
  • 2,299
  • 2
  • 20
  • 41
1
vote
2 answers

how to setup two user_id columns in one model in rails?

I have two models class User has_many :disputes end class Dispute belongs_to :user end So Dispute has :user_id, but my problem is that a Dispute has 2 sides - the claimant and the indicted, both of which are users. I tried to solve this…
anndrew78
  • 196
  • 1
  • 20
1
vote
2 answers

Issue with saving and validating temporary virtual attributes which come from form inputs

I have two models: Project. Item. A project has many items, and an item belong to a project. class Project < ActiveRecord::Base attr_accessor :main_color, :secondary_color, :tertiary_color has_many :items accepts_nested_attributes_for…
1
vote
2 answers

Connecting two models belongs_to/has_many and selecting via dropdown in form

I am rails beginner and I am facing a basic problem. I have found a couple of solutions but none of them fully describe my problem. I have two models: Contact and Group Group has_many :contacts Contact belongs_to :group (Through devise there is a…
Jan
  • 239
  • 1
  • 4
  • 17