Skip to content

Instantly share code, notes, and snippets.

@1990prashant
Created March 16, 2016 06:47

Revisions

  1. Prashant Kumar Mishra created this gist Mar 16, 2016.
    15 changes: 15 additions & 0 deletions controller.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    def comment
    @comment = Spree::Post.new(post_params)
    @comment.attributes = {user_id: current_spree_user.id}
    if @comment.save
    render json: {
    success: true,
    comment: render_to_string((@comment.parent_id.blank? ? 'spree/shared/_previous_comments' : 'spree/shared/_comment_line_item'), :layout => false, :locals => { :comment => @comment })
    }
    else
    render json: {
    success: false,
    errors: @comment.errors.full_messages.join(", ")
    }
    end
    end