I've added a theming directory to my app as described here, using prepend_view_path
. It works as expected. I can now add a view structure in my app under app/themes/my_theme/views
Now, I want to be able to override erb
templates by dropping in a
.liquid
file, which will render right off the controller action.
For example, I want to override app/views/pages/home.html.erb
:
<h1><%= t 'it_works' %></h1>
...with app/themes/my_theme/views/pages/home.liquid
<h1>It works with {{ "liquid" }}</h1>
I don't want to have to specify an array of view paths (upkeep would be awful), but just add .liquid
as a layer to the templating engine. Maybe, however, have a blacklist of protected views that cannot be overridden (such as app/views/admin/*
)
Do you have a liquid template handler? Otherwise Rails won't know what you want to do with .liquid files. See this blog post: http://royvandermeij.com/blog/2011/09/21/create-a-liquid-handler-for-rails-3-dot-1/
For your second question: not using a theme for
app/views/admin/*
you should make sure you have an AdminController that does notprepend_view_path
.According to the documentation you can use
prepend_view_path
Add the following to your ApplicationController:
So Rails should then look for any views in your theme specific directory in preference to the default views in app/views/**/*