Last active
December 28, 2015 19:19
-
-
Save siliconsenthil/7549154 to your computer and use it in GitHub Desktop.
This code is after moving logic to model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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