-
Rails 2.1 + Theme Plugin
Posted on June 13th, 2008 16 commentsSo you’ll get some crazy errors if you’re using the theme support plugin w/ the patch explained here. You’ll need to change your render_file method to look like this (thanks to Nate’s comment for making the code work for everybody):
def render_file(template_path, use_full_path = false, local_assigns = {}) search_path = [ "#{RAILS_ROOT}/themes/#{controller.current_theme}/views", # for components "#{RAILS_ROOT}/themes/#{controller.current_theme}", # for layouts ] @finder.prepend_view_path(search_path) local_assigns['active_theme'] = get_current_theme(local_assigns) theme_support_old_render_file(template_path, use_full_path, local_assigns) endAnd boom, works.
Uncategorized16 responses to “Rails 2.1 + Theme Plugin”

-
Great! Damien pointed me to this plugin. Going to try it right now.
-
If still got one issue with moving to Rails 2.1..
See the following code:
http://www.pastie.org/216402It keeps rendering basic theme partials instead of the themed one.. hope you can help?! (couldn’t find any email address on the site.. so put it in a comment).
-
Hmm.. it seems that the above code never turns to the render_file_with_theme_support method…
-
You have the theme support plugin installed, and put in this patch, but it’s not rendering any of your themed files?
-
This also screws with assert_template in tests for some reason. assert_template “new” now has to be assert_template “new.html.erb” for example as a crappy workaround. looking into it…
-
@Nate
Ugh.That’s no good. We have a small demo app that I made it work for, but haven’t done much aside from that. If you get it going, let me know, since I think we’ll be moving to Rails2.1 eventually on our bigger app.
Thanks!
-
I’m curious why we need to do the finder.pick_template? If you stick the paths to the search path, isn’t Rails supposed to be able to find the template on its own now these days with 2.1? So I changed the render code above to be:
So all it’s essentially doing is prepending the new view paths out of the themes directory and letting rails find them on its own by calling the old aliased render, and it seems to do the job. And it also doesn’t screw with @first_render apparently, which makes assert_template work again as expected.
-
@Nate
Nice catch, sir. That clearly isn’t necessary (since it works just fine without it, and reportedly better), so I’m going to update the post (and my local code!) to reflect it.Thanks!
-
I’ve just tried this patch, but I keep running into an error with @finder:
NoMethodError (You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.prepend_view_path):
/vendor/plugins/theme_support/lib/patches/actionview_ex.rb:16:in `render_file’Should the @finder variable be set elsewhere?
Thanks.
-
Oops, my bad. Looks like I was attempting this against rails edge as my git submodule wasn’t checked out on the right tag.
Have now got it working fine with Rails 2.1.0 but edge seems to have already changed a fair bit with regards to templates.
-
Steffen July 8th, 2008 at 08:09
Hmm… even the last one didn’t work if I was rendering partials directly from controller. The reason seems to be that all this only affects the TemplateFinder, if there is a render command inside a template. Else, the render method in ActionController::Base is used, which is uneffected by the theme_support patches.
An alternative solution: use ActionController::prepend_view_path directly from a before_filter. That helps in my case, and makes all patches to ActionView::Base unnecessary.
-
Hi!
I still have some problems with the Theme-Plugin. Or maybe I just don’t understand right.
After changing to the theme_plugin I deleted my public/images, public/javascripts directories and moved the contents into the /themes/default/-Folders.
But now it seems that these files aren’t used. When I use the command “theme_javascript_include_tag ‘default’, ‘prototype” the error is:
“Cannot read file /themes/prototype/javascript/”
thats surely wrong, because prototype is the library to load?Also, do I now have to use theme_image_tag instead image_tag? Seems so, because the theme_plugin otherwise searches in public/images.
-
joost July 27th, 2008 at 08:01
I have the following problem (using Theme Plugin + Globalize):
It doesn’t seem to work when rendering inside blocks, like:
render :page do RJS stuff!
Same for yield magic:
content_for :something do
…
endAny ideas?
-
Do those use different helpers to find the templates?
If you try to do it from the console, can you trace it to see where it’s looking?
-
I’ve collected together the bits and pieces of patches, and uploaded to github: http://github.com/aussiegeek/theme_support
-
I have tried so many versions of this, and I cannot seem to get it to work, specifically, I’m at the exact same problem I had when trying to do this myself – layouts do not seem to get loaded. Anyone having this issue and how the hell do I get around it? I’ve moved all my view files into themes/default. I’m currently using Rails 2.1.0.
-


joost June 16th, 2008 at 00:47