[Sorry if this has been asked before I seem to have hit a super-tricky part of rails ActionView… if so please kindly point me in the right direction I’ve been googling but I’m afraid this knowledge might be lost back in 2013…]
0
I am building a gem.
You can see my super-simple gem here: GitHub - jasonfb/xyz_gem: testing gem/rails loading quirks of gem building — this is experimental only
It’s just a shell.
What I want to know today is what tells Rails that it should load my Gem’s views, that is, the views in app/views/ when loading partials?
I have a rails app called XyzGemTest (not the gem) that uses the gem via a local path include
I have view that I am rendering simply at HellosController for demonstration.
The view renders this:
this is in the app code
<%= render partial: 'hello_world' %>
Please note that my partial hello_world
is inside of my Gem-- at app/views/_hello_world.erb (although I tried also moving it to app/views/xyz_gem/_hello_world.erb)
When I load my app, I get this common error:
ActionView::Template::Error (Missing partial hellos/_hello_world, application/_hello_world with {:locale=>[:en], :formats=>[:html], :variants=>, :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]}. Searched in:
- “/Users/jason/Work/CommonCoreJS/XyzGemTest/app/views”
- “/Users/jason/.rvm/gems/ruby-2.6.4/gems/actiontext-6.0.3.2/app/views”
- “/Users/jason/.rvm/gems/ruby-2.6.4/gems/actionmailbox-6.0.3.2/app/views” ): 1: this is the wrapper 2: 3: 4: <%= render partial: ‘hello_world’ %>
app/views/hellos/index.erb:4
As you can see, this blank Rails 6.0 app is trying to load view files from presisely 3 places: (1) my own app’s app/views folder (NOT the gem) (2) actiontext (3) actionmailbox
What I’m asking here is what do I need to do to my Gem to make it so that ActionView will include my gem’s app/views/ folder in the ‘chain’ of paths that it looks for?
You are welcome to fork & refactor my Github repo above. which is at
(I know for example that my gem is supposed to have a lib/ folder and this folder must have a file named xyz_gem.rb …… I will add that now and see if it helps)