Skip to content

Instantly share code, notes, and snippets.

@Yama-to
Last active September 9, 2015 03:31
Show Gist options
  • Save Yama-to/2bfa3ee68e82716deba7 to your computer and use it in GitHub Desktop.
Save Yama-to/2bfa3ee68e82716deba7 to your computer and use it in GitHub Desktop.
モモンガでも使えるAjax(えいじゃっくす) − 投稿したコメントをリロードせずに表示しよう ref: http://qiita.com/Yama-to/items/377f8a92cf30a3ebf454
def create
Comment.create(comment_params)
@prototype = Prototype.find(params[:id])
end
$('#comment_field').val('');
$('#comments').html(
'<%= j(render partial: 'prototypes/comment', collection: @prototype.comments) %>'
);
#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"
%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