Skip to content

Instantly share code, notes, and snippets.

@radar
Created April 22, 2012 02:06
Show Gist options
  • Save radar/2440816 to your computer and use it in GitHub Desktop.
Save radar/2440816 to your computer and use it in GitHub Desktop.

Campaigning Thingo

The models you have are: Campaign, User, Card, Question and Response. Here's how I would do it using ActiveRecord

Campaigns exist with questions and responses by users. The Campaign model would look like this:

class Campaign < ActiveRecord::Base
  has_many :questions
  has_many :responses, :through => :questions
end

This means that the questions table has a campaign_id on it, and responses would have question_id. The Question model looks like this:

class Question < ActiveRecord::Base
  belongs_to :campaign
  has_many :responses

Responses belong to a user, and also a question. The Response model:

class Response < ActiveRecord::Base
  belongs_to :question
  belongs_to :user
end

The User model looks like this:

class User < ActiveRecord::Base
  has_many :responses
end

I don't know what cards have to do with any of this, since these are represented in the physical world only, it seems. Perhaps this could be represented in the database too, but I don't see a need for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment