![]() | Adding a render in an initializer doesn't appear to register properly |
|
23 Feb 2011, 17:53
Noah Hendrix (1 post) |
I’m using the technique from the first chapter to register a renderer for a csv file type. Instead of making an entire engine for it, I am attempting to just place it in an initializer. ActionController::Renderers.add :csv do |filename, options|
send_data(render_to_string(options), :filename => ”#{filename}.csv”, :type => “text/csv”, :disposition => “attachment”) However, it doesn’t appear to be working. I can see that it gets added to ActionController::Renderers::RENDERERS, but when I visit a csv file in the browser it simply displays it inline. Is an initializer not the place to create a renderer? |
|
07 Mar 2011, 20:48
José Valim (26 posts) |
Noah, an initializer should work fine, except if something else (like a plugin) is forcing ApplicationController to be loaded too early, so your changes won’t propagate to the controller in your application. Ideally, an initializer is not a good place as well. If you want to leave it in your application, I would move to the lib folder and load it quite soon in the stack, just after Bundler.require and before the application definition. |
| You must be logged in to comment |

