我正在写一个需要角度的rails gem,所以我将它添加到我的gem的依赖项中:
s.add_dependency "angularjs-rails", "~> 1.6.2"
现在,我应该如何包括角度?我试图直接在我的gem的主要js脚本中添加它,但sprockets因这种错误而失败:
couldn't find file 'angular' with type 'application/javascript'
Checked in these paths:
...
/Users/mac/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/bundler/gems/grid_builder-rails-be353dff709f/app/assets/javascripts
/Users/mac/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/bundler/gems/grid_builder-rails-be353dff709f/app/assets/stylesheets
...
当我尝试在使用我的gem的应用程序中包含angular时,在包含我的gem脚本之前,错误是完全相同的......
所以我应该指定我的gem需要在应用程序Gemfile中添加angularjs-rails,还是有更好的方法来执行此操作?
答案 0 :(得分:0)
正如Richard Peck所提议的那样,我在gem的模块文件中需要angularjs-rails,一切都很顺利:
require 'angularjs-rails'
module GridBuilder
module Rails
require 'grid_builder/rails/engine'
require 'grid_builder/rails/version'
require 'grid_builder/rails/helper'
end
end
在我宝石的js剧本中:
//= require angular
谢谢:)