I followed http://railscasts.com/episodes/245-new-gem-with-bundler to make a gem with bundler and this is great for gems where i only need a lib, is there a standard practice for gems where i need to create mini apps with assets/controllers/models/views ?
You would be looking to create an engine at that point. Reading the Engines Guides guide should give you a great start on that.
The bare-bones components you need inside your gem are a file at lib/your_gem.rb
that serves the purpose of simply requiring whatever it is your gem needs. If your gem has no other dependencies, then it looks like this:
require 'your_gem/engine'
One line, so much power. The lib/your_gem/engine.rb
file it requires has this code in it:
module YourGem
class Engine < Rails::Engine
end
end
By simply inheriting from Rails::Engine
, this triggers an inheritance hook on Rails::Engine
that notifies the framework that there is an engine at the location of your gem.
If you then create a file at app/assets/stylesheets/your_gem/beauty.css
, you can then include that in your application (assuming you have the asset pipeline enabled, of course) using this line:
<%= stylesheet_link_tag "your_gem/beauty" %>
Now that I've given you the short version of it, I really, really, really recommend reading the Engines Guide top to bottom to better understand it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With