Skip to content

Instantly share code, notes, and snippets.

@akirill0v
Created March 25, 2014 18:03
Show Gist options
  • Save akirill0v/9767564 to your computer and use it in GitHub Desktop.
Save akirill0v/9767564 to your computer and use it in GitHub Desktop.
class Kudos < AR
belongs_to :reciver #кто дает
belongs_to :target_user #кому дает
end
class KudosType < Kudos
# тут бует один инклуд, ссылка будет в переписке
def target_user=(user_email)
# найдем или построим пользователя
user = User.where(email: user_email).first_or_initizlize(email: user_email)
super(user) # присвоим связи этого пользователя
end
end
# Где-то в контроллере
def create
@kudos = KudosType.new(params[:kudos])
@kudos.save if current_user.can_create?(@kudos)
respond_with @kudos
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment