Xavier Shay
Xavier Shay

Reputation: 4127

Sharing partials across multiple Rails applications

I have a set of partials (user/_comment.html.erb, for example) that I want to share across multiple Rails applications.

What is the best way to do this? I am leaning towards an Engine at the moment, because I would also like to share some models, but can't figure out how to integrate them.

I have tried creating a Rails engine gem with app/views/users/_comment.html.erb and adding it to the Gemfile of the main Rails application, but it cannot find the view (ActionView::MissingTemplate). Is there an official way to add the engine to the view path?

Upvotes: 3

Views: 433

Answers (1)

Paweł Gościcki
Paweł Gościcki

Reputation: 9604

What you have described should work. If you add a Gem and especially if it's an engine, Rails adds this gem's app/ directories to the load path(s) and it should, well, work :) Your render call should be something like: render "users/comment". Oh, and after bundling the gem, the app needs to be restarted as well. Can't think of anything else.

Upvotes: 1

Related Questions