Skip to content

Instantly share code, notes, and snippets.

@dmitry
Created November 1, 2009 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitry/223480 to your computer and use it in GitHub Desktop.
Save dmitry/223480 to your computer and use it in GitHub Desktop.
self.include_root_in_json = false
def export
json = to_json(:include => [:door_profile, :door_lift, :door_hinge, :door_handle, :door_glass], :except => [:created_at, :updated_at, :door_id, :id, :order_id, :user_id])
attributes = ActiveSupport::JSON.decode(json)
%w[door_profile door_lift door_hinge door_handle door_glass].each do |v|
if attributes[v]
attributes["#{v.to_s}_attributes"] = attributes[v]
attributes.delete(v)
end
end
ActiveSupport::JSON.encode(attributes)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment