I’m calling render partial
from a helper in a custom gem I’m authoring, and I’m having trouble getting it to load an ERb template that is also in the gem. I’ve used append_view_path
to add the directory inside the gem containing the *.html.erb
templates, and I’ve confirmed that ActionController::Base.view_paths
does indeed have the additional search path when render
is called. But when I call the helper from a sample application, I get an exception claiming it can’t find the partial, and though it lists the paths it’s searched, the additional directory path isn’t included. How can the view paths include the required directory, while the exception suggests it does not?
Here’s an excerpt from the logged exception:
Missing partial /_bulma_index_header with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]}.
Searched in:
* "/home/kweller/Projects/mg/bfr/app/views"
* "/home/kweller/.rbenv/versions/3.1.2/gemsets/bfr/gems/actiontext-7.0.4/app/views"
* "/home/kweller/.rbenv/versions/3.1.2/gemsets/bfr/gems/actionmailbox-7.0.4/app/views"
The path I added is missing from the error message, but it’s present in ActionControllerL::Base.view_paths
as /home/kweller/Projects/mg/bulma_form_rails/views
. Why is render
ignoring this additional search path?
Here’s how I add the view path:
VIEW_PATH = 'lib/bulma_form_rails/views'
@@bulma_form_initializer = Proc.new do
ActionView::Helpers.send :include, Helpers
ActionController::Base.class_eval do
append_view_path File.join(Gem.loaded_specs['bulma_form_rails'].full_gem_path, VIEW_PATH)
And here is where the helper method tries to use it:
render partial: '/bulma_index_header', locals: {name: name, models_path: models_path}