Skip to content

Instantly share code, notes, and snippets.

@entp
Created September 9, 2009 01:59
Show Gist options
  • Save entp/183398 to your computer and use it in GitHub Desktop.
Save entp/183398 to your computer and use it in GitHub Desktop.
class ApiSerializer < ActiveRecord::Serialization::JsonSerializer #:nodoc:
def serializable_record
@host_name = @options.delete :host
@is_supporter = @options.delete :supporter
@site_permalink = @options.delete :site_permalink
@site_prefix = nil
super
end
def site_prefix
@site_prefix ||= "#{@host_name}/#{@site_permalink}"
end
end
class Faq::JsonSerializer < ApiSerializer
def serializable_record
hash = super
if @host_name
id = hash.delete('id')
prefix = "#{site_prefix}/faqs/#{id}"
hash[:href] = prefix
if section_id = hash.delete('section_id')
hash[:section_href] = "#{site_prefix}/sections/#{section_id}"
end
end
hash
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment