Skip to content

Instantly share code, notes, and snippets.

@jordanthomas
Forked from anonymous/comments_controller.rb
Created December 12, 2012 04:41
Show Gist options
  • Save jordanthomas/4264907 to your computer and use it in GitHub Desktop.
Save jordanthomas/4264907 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
#Object
# by_admin?: true
# content: ""
# created_at: null
# id: null
# report_id: 1
# updated_at: null
# user_id: 1
# __proto__: Object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment