Skip to content

Instantly share code, notes, and snippets.

@gary
Created February 5, 2009 04:00
Show Gist options
  • Save gary/58542 to your computer and use it in GitHub Desktop.
Save gary/58542 to your computer and use it in GitHub Desktop.
# make life in JavaScript more readable by wrapping the Objects needed
# to update after a {successful,failed} save in a named Hash, which will
# serialize an Object with key-named properties. big slick.
def pretty_json(subscription, params={})
# camelCased ruby is heresy, and is merely following the naming
# conventions of its destination environment
if subscription.valid?
{ :newspaperName => @mobile_alert.newspaper.name,
:mobileAlert => @mobile_alert,
:editLink => edit_subscription_modal_window(@mobile_alert.id,
subscription.id),
:destroyLink => url(:destroy_mobile_alert_subscription,
:mobile_alert_id => @mobile_alert.id,
:id => subscription.id)
}
else
{ :validation => subscription.errors.to_a }
end.merge(params)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment