-
-
Save CortYuming/88ccd49bc9b41e371dc0 to your computer and use it in GitHub Desktop.
RE: 『RE: Rails4 でお気に入りをオン・オフするトグルボタンみたいのをやってみるメモ』の宿題
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
| def fav | |
| @comment = Comment.find(params[:id]) | |
| if @comment.favorites.blank? | |
| current_user.favorites.create(comment: @comment) | |
| else | |
| current_user.favorites.where(comment: @comment).destroy_all | |
| end | |
| end |
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
| $('#<%= dom_id @comment %>').html("<%=j render 'favorites/favorite_button', comment: @comment %>"); |
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
| resources :comments do | |
| member do | |
| post :fav | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
元ネタ
『Rails4 でお気に入りをオン・オフするトグルボタンみたいのをやってみるメモ』
http://d.hatena.ne.jp/CortYuming/20140617/p1
返答
『RE: Rails4 でお気に入りをオン・オフするトグルボタンみたいのをやってみるメモ』
https://gist.github.com/yohfee/07556e4c46da1819fc71
これの宿題やってみますた。
あとんす。