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
0 answers

Rails way to organize models

So the stroy is very simple: if I have some groups of models, very closely related to each other within a each group (and not so closely between the groups) I can organize them in modules (so that each group will have its own folder in the models…
Almaron
  • 4,127
  • 6
  • 26
  • 48
1
vote
0 answers

Rails 3.2.1 models in modules

I have many models in my applications and some of them are closely related to each other so I decided to group them up and make modules. Here is what I did as an example: http://pastebin.com/qqELTd2k Now I am curious about three things. Firstly: do…
Almaron
  • 4,127
  • 6
  • 26
  • 48
1
vote
1 answer

Paperclip attachment shared by 2 models

I am trying to roll out my own e-commerce solution. Extending the depot application explained in the Pragmatic Web Development with Rails book. I am currently trying to figure out attachments. Essentially I want Product and Product_Variants to use…
frishi
  • 862
  • 1
  • 10
  • 27
1
vote
2 answers

Only one instance of a Rails Model

I have blog with only one author. Author encapsulates many different fields that will appear on every page. Do I Need an Author Model? Where should I store my author (I use MongoDB) and how can I do that in the rails way?
Dmitry Zhlobo
  • 369
  • 2
  • 10
1
vote
2 answers

How do I count records that satisfy a condition in a associated model?

Okay, what I've got is two models... Jiraissue: class Jiraissue < ActiveRecord::Base # JIRA uses a singular table name for this model set_table_name 'jiraissue' has_one :severity end Severity: class Severity < ActiveRecord::Base belongs_to…
Bruce P. Henry
  • 412
  • 1
  • 4
  • 14
1
vote
3 answers

Rails associations - how can I set up associations for different varieties of users?

I'm creating a web app which consists of schools, courses, students, and teachers. A school can have many courses and a course has one teacher and many students. The problem I am running into is that a single user could be a teacher of one course,…
Deonomo
  • 1,583
  • 3
  • 16
  • 25
1
vote
1 answer

Model has_many AND has_many :through in one?

I have a set of categories, belonging to a category set. These categories can themselves have a mix of categories (self-referential) and also questions. The models and their relationships are defined & visualized as follows: class CategorySet <…
Pete Hamilton
  • 7,730
  • 6
  • 33
  • 58
1
vote
0 answers

Multi Model Wizard Form Rails 3

I've been banging my head on this problem for a while now, But can't seem to find a reasonable answer. I'll describe my problem and my setup. Hopefully I can get some ideas! The Problem Im trying to create a "wizard" form where the user can click…
1
vote
0 answers

rails nested has_many display field and model design pattern

I want to create a view to has_many model which will list all the answers to a topic. The relation between the question and answers is really simple, but everything else is getting too complex. The user should have the option to add answers to…
1
vote
2 answers

Howto structure rails user friendships model?

I need to create a user Friendship (user1_id, user2_id) model which connects users. I would like to avoid having to create two Friendship records for every user / friend as a friendship goes both ways. How would you do this so while having a…
1
vote
3 answers

RoR3 Model associations (Game belongs_to two Players)

I'm really new to Ruby on Rails 3 and I'm working on a simple chess game application. I plan to create the following models: rails g model Player name:string rails g model Game player_id_white:int player_id_black:int title:string rails g model…
1
vote
1 answer

Correct design: a Post can have one User (author) plus many Users (tagged users)

I have a situation where I'm getting a bit stuck. A Post can have a User (as an author), and a Post can also have many Users (as a post can have other users tagged in it). In my Post model: belongs_to :user has_and_belongs_to_many :users In my…
Daniel
  • 245
  • 3
  • 10
1
vote
0 answers

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 tables). I have a model that looks something like…
lck
  • 11
  • 1
1
vote
1 answer

How to add property in module in Rails CouchRest Model to support multiple inheritance?

In my class, I want to include multiple modules. Each module can define its own property to persist in couchDB. Here is an example: module Owner property :name end module Animal property :type end class Cat include Owner include…
PokerIncome.com
  • 1,708
  • 2
  • 19
  • 30
1
vote
0 answers

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 similar attributes, like title, year, etc. but each…
Rich Steinmetz
  • 1,020
  • 13
  • 28