Open michaelmarconi opened 12 years ago
Hi Michael ... I have run into the same damn thing!!
You are not missing anything obvious.
I ran into this problem when I ported http://jsonify.org to Rails 3.1; it seems to be caused by the implementation of to_json in ActiveSupport which now relies on MultiJson ... I have not had time to pin down what exactly in ActiveSupport caused the breakage.
So, what I did for http://jsonify.org was to actually use client-side formatting in JavaScript (which was fine for me).
Now, to be honest, I wasn't overly concerned about this because the pretty printing in Jsonify really should not be used in production IMO. There is an inherent performance penalty -- Jsonify pretty printing leverages the JSON.pretty_generate (or, now with MultiJson, it passes :pretty => true which gets translated and passed down to JSON as the set of options needed for pretty generation -- that requires the JSON string to be reparsed and emitted back out. So, I basically decided to leave this as somewhat of an open bug that was not a "show stopper".
Is it a show stopper for you?
Let me know,
Bill
On Feb 14, 2012, at 1:37 PM, Michael Marconi wrote:
Hi - I've followed your instructions about getting pretty printing in a Rails 3.1 app working to no avail. I'm including my application.rb here:
require File.expand_path('../boot', __FILE__) require 'rails/all' if defined?(Bundler) # If you precompile assets before deploying to production, use this line Bundler.require(*Rails.groups(:assets => %w(development test))) # If you want your assets lazily compiled in production, use this line # Bundler.require(:default, :assets, Rails.env) end module MyApp class Application < Rails::Application # Configure the default encoding used in templates for Ruby 1.9. config.encoding = "utf-8" # Configure sensitive parameters which will be filtered from the log file. config.filter_parameters += [:password] # Pretty-print JSON output config.jsonify_format = :pretty # Enable the asset pipeline config.assets.enabled = true # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.0' end end
The output all runs on a single line. Am I missing something obvious, like a 'require' statement?
Reply to this email directly or view it on GitHub: https://github.com/bsiggelkow/jsonify-rails/issues/7
Hi Bill - no crisis; I've been using the excellent JSON formatter. Unfortunately, so has everyone else, so it's not very responsive at the moment!
Perhaps you should remove the documentation for pretty-printing if you're not planning on making it work in the future.
Otherwise, your project is certainly making my life easier, so thank you!
Best, Michael
Thanks for pointing out jsonformatter -- I had not used that.
I would definitely like to make the pretty printing work -- and it does outside of Rails (but who is using Ruby outside of Rails 8-) -- anyway, I just need to do the digging into ActiveSupport ... it's only one of 8000 things on my to-do list :)
Glad that Jsonify is helping you out -- by the way ... here's just the short little JS function (in CoffeeScript) to do my client side formatting
prettify = (json) -> try JSON.stringify(JSON.parse(json), null, 4)
On Feb 15, 2012, at 9:55 AM, Michael Marconi wrote:
Hi Bill - no crisis; I've been using the excellent JSON formatter. Unfortunately, so has everyone else, so it's not very responsive at the moment!
Perhaps you should remove the documentation for pretty-printing if you're not planning on making it work in the future.
Otherwise, your project is certainly making my life easier, so thank you!
Best, Michael
Reply to this email directly or view it on GitHub: https://github.com/bsiggelkow/jsonify-rails/issues/7#issuecomment-3981600
Hi - I've followed your instructions about getting pretty printing in a Rails 3.1 app working to no avail. I'm including my application.rb here:
The output all runs on a single line. Am I missing something obvious, like a 'require' statement?