Move "created" and "as_json" from Comment to CommentDecorator

openid
Marcin Kulik 13 years ago
parent e26875f68a
commit 32b2cbed35

@ -1,9 +1,22 @@
class CommentDecorator < ApplicationDecorator
decorates :comment
def as_json(*args)
data = model.as_json(*args)
def created
created_at && created_at.strftime("%Y-%m-%dT%H:%M:%S")
end
def as_json(opts = nil)
opts ||= {}
options = {
:include => { :user => { :only => [:id, :nickname, :avatar_url] } }
}
options.merge!(opts)
data = model.as_json(options)
data['processed_body'] = markdown(data['body'])
data['created'] = created
data
end

@ -9,19 +9,4 @@ class Comment < ActiveRecord::Base
attr_accessible :body
def created
created_at && created_at.strftime("%Y-%m-%dT%H:%M:%S")
end
def as_json(options = {})
super({
:include => {
:user => {
:only => [:id, :nickname, :avatar_url]
}
},
:methods => [:created]
}.merge(options))
end
end

Loading…
Cancel
Save