I have an application which serves more than one website. Similar to Stack Exchange, these several sites behave very similarly to each other.
Given the following views directory structure:
views/
shared/users/index.html.erb
app1/users/index.html.erb
app2/users/
How can I re-write the default template rendering in Rails so that
Thanks in advance
I know you already accepted an answer for this, but I don't think you need to create your own template resolver.
If I understand your question correctly, you are trying to "theme" your views depending on some aspect of the current state of the app. I have done the same thing previously using this dandy little controller method:
prepend_view_path "app/views/#{current_app_code}"
Throw this in a before_filter in your application controller, and all your controllers will obey:
class ApplicationController < ActionController::Base
before_filter :prepend_view_paths
def prepend_view_paths
prepend_view_path "app/views/#{current_app_code}"
end
end
Now rails will first look for "app/views/app1/users/index.html.erb" when "/users" is requested if "app1" is the current app.
If it doesn't find it there, it rolls back to the default location at "app/views/users/index.html.erb".
Hope this gives you another alternative.
I believe that you'll have to code your own Template Resolver. Perhaps this blog post can help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With