Skip to content

Instantly share code, notes, and snippets.

@siliconsenthil
Last active December 28, 2015 19:19
Show Gist options
  • Save siliconsenthil/7549154 to your computer and use it in GitHub Desktop.
Save siliconsenthil/7549154 to your computer and use it in GitHub Desktop.
This code is after moving logic to model
class CommentsController < ApplicationController
def create
Comment.create(params[:comment])
render :text => 'Success'
end
end
#################################################
class Comment < ActiveRecord::Base
belongs_to :event_user
attr_accessible :text, :event_user
delegate :uid, to: 'event_user.user'
after_create do
FayeClient.broadcast("/event_#{event_user.event_id}_comments", as_json)
end
def as_json
super.merge(uid: uid, text: ERB::Util.html_escape(text))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment