R – Does it make sense to create a Ruby gem that consists of only Rails template partials

rubyruby-on-railsrubygems

I'm trying to understand what does and doesn't work in Ruby gems (primarily from the perspective of creating one for myself to reuse functionality from one project to the next).

When you create a Ruby gem, are you limited to including only Ruby functionality or could you create a gem that consisted of Rails templates, CSS files and JavaScripts?

If so, how would the user of the gem access those resources in a Rails project (besides adding a 'config gem' statement to the environment.rb file?

Best Solution

No it doesn't. Gems are code libraries, not static files.

When you load a gem, you don't move the files to your public directory. You load a ruby file and get access to a module. So, you can only execute ruby code within it.
But, your ruby code can give you some helpers allowing you to easily build your design for example.

If you want to include some static file resources in each of your ruby projects, I'd see two solutions:

  • Create a template project, including all the css, javascript etc. that you use every time. You can take suspenders as an example of this.

  • Create a new repository with all these static files and add it as a submodule (with git or svn) and include it in each of your projects.

The first solution would be my favorite, but you might want to take the other one.

Related Question