1

I'm working with the Solidus gem that has its own views, and I want to make a gem that overrides some of its views.

Modifying this in a project or custom app is easy since I just have to write the file with the namespace and the name in my project folders, but, what if I want to gemify my result? In other words, I want to write this in my Gemfile:

gem 'first_gem'
gem 'my_new_gem'

and expect that app/views/controller/file.html.erb of first_gem to be overriden by the one I have in my_new_gem.

I made a .gem file with modified views in app/views but when I install it via gem install my_new_gem.gem and include it with Bundler in a project, views doesn't change anymore.

I've been stuck for hours with this and actually tried this:

  • Load gems in order with Bundler.require.
  • List Solidus gem as a dependency in my gem. My gem is required after the dependency as intended, but doesn't work anyway.

Maybe I'm trying something that even isn't working. Maybe I'm not understanding Rubygems at all or maybe I have to preload files with a lib script. I'm getting lost where to start or where to find information about this.

I know I can use overrides in Solidus, but I'm changing some layouts and some divs that don't have hooks, so I think this is the only way to go.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
S. Soto
  • 21
  • 8
  • you need to make sure that rails knows where to look for the templates. `prepend_view_path` could be something that works. another approach would be to provide a rake task that copies the files into the project instead of "linking" them through a gem. – phoet Oct 10 '16 at 18:59
  • I googled that concept and didn't like it that much because I didn't want to create a controller since I'm just handling views, but checking out other links on the same query I found this: http://stackoverflow.com/a/26606926/6900659 I think this would work in my case, because on initialization I would be loading the gem contents. Btw, thinking about it, a rake task or a generator would be a better idea if I want to change the templates in the scope of the new project. I'm providing an answer for this when I test it out. Thanks! – S. Soto Oct 10 '16 at 20:31

0 Answers0