Skip to content

Instantly share code, notes, and snippets.

Created December 12, 2012 04:23
Show Gist options
  • Save anonymous/4264846 to your computer and use it in GitHub Desktop.
Save anonymous/4264846 to your computer and use it in GitHub Desktop.
class CommentsController < ApplicationController
respond_to :html, :json
def create
@report = Report.find(params[:report_id])
@comment = @report.comments.build(params[:comment])
@comment.user = current_user
respond_with @report, @comment, :methods => [:by_admin?]
end
end
<%= form_for [@report, @report.comments.build], :remote => true, :html => {:'data-type' => 'json'} do |f| %>
<%= f.text_area :content, :rows => '3', :placeholder => 'Type your comment here.' %>
<%= f.submit %>
<% end %>
$(document).on 'ajax:success', '#new_comment', (e, data, status, xhr) ->
console.log data
# logs @comment as json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment