This project is archived and is in readonly mode.
Custom template handlers are broken in test (and maybe production)
-
thedarkone
Hi Jeff, your test doesn't pass because you are messing up
controller_path, if you comment out the line everything works fine.Could you please make a smallish 1 controller, 1 view app on Github (or simply zip and attach it here) to demonstrate the issue?
-
Jeff Dean
Thanks for taking a look at this so quickly - I see what you mean about the view paths. I've attached a sample app that demonstrates the problem:
Run in development environment:
- script/server
- open localhost:3000
- there are 4 links on the homepage - clicking each one you will see "this works"
Run in production environment:
- script/server -e production
- open localhost:3000
- clicking each link on the homepage you will see that none say "this works"
Run the tests:
- ruby test/functional/third_party_extension_controller_test.rb
- you'll see the same results as the production environment
To get this to work, I created and registered a very simple template handler that looks like this:
class CustomTemplateHandler < ActionView::TemplateHandler def render(template, assigns) "it works" end endI spent some time trying to reproduce this in the the actionpack tests, but I haven't made any progress.
-
Jeff Dean
Quick note - the sample app has one controller with 4 actions:
- Just a template (no action)
- An empty action with a template
- Using render :template with no extension
- Using render :template with an extension
So this issue seems to affect multiple ways of rendering templates with custom template handlers.
-
thedarkone
Thanks for the app, the reason that it all breaks down for you is that you are registering your template handler after the Rails has initialized (and in production loaded and compiled all the templates).
You need to move the "handle-registering" code into an initilizer (
config/initializers) or intoRails::Initializer.run do |config|; endblock. -
Jeff Dean
Thanks again for taking the time to look at this. That did the trick. This can be closed.
-
CancelProfileIsBroken
- State changed from new to invalid
