Last active
September 9, 2015 03:31
-
-
Save Yama-to/2bfa3ee68e82716deba7 to your computer and use it in GitHub Desktop.
モモンガでも使えるAjax(えいじゃっくす) − 投稿したコメントをリロードせずに表示しよう ref: http://qiita.com/Yama-to/items/377f8a92cf30a3ebf454
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
-# 変更なし |
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 create | |
Comment.create(comment_params) | |
@prototype = Prototype.find(params[:id]) | |
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
$('#comment_field').val(''); | |
$('#comments').html( | |
'<%= j(render partial: 'prototypes/comment', collection: @prototype.comments) %>' | |
); |
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
#comments | |
= render partial: 'prototypes/comment', collection: @prototype.comments | |
%div | |
= form_for @new_comment, remote: true do |f| | |
%h4 Write a comment | |
= f.text_area :text, id: "comment_field" | |
= f.submit :comment, class: "btn btn-primary" |
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
%div | |
= render @prototype.comments | |
%div | |
= form_for @new_comment do |f| | |
%h4 Write a comment | |
= f.text_area :text | |
= f.submit :comment, class: "btn btn-primary" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment