Created
July 24, 2008 19:50
-
-
Save dustym/2270 to your computer and use it in GitHub Desktop.
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 Array | |
def to_json(options = {}, &block) #:nodoc: | |
"[#{map { |value| ActiveSupport::JSON.encode(value, options, &block) } * ', '}]" | |
end | |
end | |
module ActiveSupport | |
module JSON | |
class << self | |
# Converts a Ruby object into a JSON string. | |
def encode(value, options = {}, &block) | |
raise_on_circular_reference(value) do | |
value.send(:to_json, options, &block) | |
end | |
end | |
end | |
end | |
end | |
class SomeModel | |
def to_json(options, &block) | |
values = {} | |
values.merge!(attributes.except(:private_stuff, :other_private_stuff)) | |
block.call(values) if block | |
values.to_json | |
end | |
end | |
class SomeController | |
def index | |
render :json => SomeModel.find(:all).to_json do |model_json_hash| | |
model_json_hash[:url] = some_model_url(some_model) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment