Created
March 25, 2014 18:03
-
-
Save akirill0v/9767564 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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