Skip to content

Instantly share code, notes, and snippets.

@SoldierCoder
Created September 28, 2011 00:43
Show Gist options
  • Save SoldierCoder/1246686 to your computer and use it in GitHub Desktop.
Save SoldierCoder/1246686 to your computer and use it in GitHub Desktop.
models and a controller question
Ok, users should get a list of campaigns (to add or withdraw support
to/from whether or not they support it now. But I also want to to
show if they are supporting it.
CampaignSupporters will hold information about which users
currently support which campaigns. But how do i get list
of all campaigns so logged in user can choose which they'd
like to support?
class Campaign < ActiveRecord::Base
has_many :campaign_supporters
has_many :users, :through => :campaign_supporters
end
class User < ActiveRecord::Base
has_many :campaign_supporters
has_many :campaigns, :through => :campaign_supporters
end
class CampaignSupporter < ActiveRecord::Base
belongs_to :campaign
belongs_to :user
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment