Last active
December 24, 2015 00:39
-
-
Save henkm/6717960 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# new model: | |
# /app/models/letsgo_user.rb | |
belongs_to :user | |
belongs_to :letsgo | |
# changes these models: | |
# /app/models/user.rb | |
has_many :letsgo_users | |
has_many :letsgos, through: :letsgo_users | |
# /app/models/letsgo.rb | |
has_many :letsgo_users | |
has_many :users, through: :letsgo_users | |
def link_to_user(user_object) | |
letsgo_users.where(user_id: user_object.id).first_or_create | |
end | |
# /app/controllers/letsgo_controller.rb | |
#create action | |
@letsgo.save | |
@letsgo.link_to_user(current_user) | |
#repost action | |
@letsgo = Letsgo.find(params[:id]) | |
@letsgo.link_to_user(current_user) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment