Tracking down not found rhtml templates in rubyonrails applications

Maybe you've seen this error before?

No rhtml, rxml, rjs or delegate template found for [view_name] (ActionView::ActionViewError)

I have a slightly special setup for my error mailer in one of my rubyonrails applications, as the mailer is not in app/models and the view not in app/views.

This used to work fine, until I changed god knows what and I realized it was broken for a little while. (by now, I, of course, know what broke it). And it was pretty hard to debug because I am using the system-wide installed rubyonrails on a shared hosting on which I don't have root access.

So at first I wanted to put some more logging in there to help me debug this beast. but for some reason, running the application with my own rails in vendor/rails was breaking everything. Can't edit the files, can't run my own, hmm.... what to do?

So today I took the few minutes it was requiring to find the right little place to put the proper logging. One thing I should add, I am an excessively lazy programmer and I like things to be short and sweet. So I did not want to copy paste a 10-15 lines function into my code. but there it is I found this one. template_exists? is only 3 lines of code, so no big deal to copy paste. there is not much chances it will change so much in the future versions of rubyonrails.

module ActionView
        class Base
                def template_exists?(template_path, extension)
                file_path = full_template_path(template_path, extension)
                logger.error(file_path)
                @@method_names.has_key?(file_path) || FileTest.exists?(file_path)
        end
        end
end

Just place this little piece of code at the end of application.rb for example and every templates that are tried will be logged in your development.log or production.log file. It helps very much to track path problems as the regular error message isn't really descriptive.

that's it, enjoy.

Tags , , , , , , , , ,

Posted in , , | Posted on 12 Nov 2006 04:37by somekool | no comments

Subscribe

my last twitter posts

Personal Links

Tags

Categories

Archives

my Xbox 360 gamertag

Copyright © Mathieu Jobin's Life and Thoughts

Tech Blue designed by Hive Designs • Ported by Free WordPress Themes and Frédéric de Villamil Powered by Typo