Rendering partial ignores view paths

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 = 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}

You mentioned that it’s present as /home/kweller/Projects/mg/bulma_form_rails/views in the load path but in your stack trace it’s /home/kweller/Projects/mg/bfr/app/views, bulma_form_rails vs. bfr. Bulma is great btw, been using that on a couple of projects.

/home/kweller/Projects/mg/bfr/app/views is the default view path for the sample application. /home/kweller/Projects/mg/bulma_form_rails/views is the one I added using append_view_path from the gem (using Gem.loaded_specs['bulma_form_rails'].full_gem_path to get the root path to the gem), and that’s the one that’s missing. Right now, I’m bringing the gem into the sample app via this line in the Gemfile:

gem "bulma_form_rails", path: "~/Projects/mg/bulma_form_rails"

And yes, Bulma is a real peach of a framework. :smiley: