我跟着http://railscasts.com/episodes/245-new-gem-with-bundler制作了一个带有捆绑器的宝石,这对于我只需要一个lib的宝石很有用,我需要一个标准的宝石练习使用资产/控制器/模型/视图创建迷你应用程序?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.