我正在关注 Thinkster 关于 Angular on Rails 的教程 ( https://thinkster.io/angular-rails#jumping-in-with-angular )。 在本教程中,我按照以下方式安装前端依赖项:
bower install angular angular-ui-router bootstrap --save
然后我需要在 application.css
中以下列方式进行引导:
*= require bootstrap/dist/css/bootstrap
*= require_tree .
*= require_self
这里是 application.js
文件:
//= require angular
//= require angular-rails-templates
//= require angular-ui-router
//= require_tree .
当我运行 rails server 时,出现以下错误,
1. couldn't find file 'bootstrap/dist/css/bootstrap' with type 'text/css'
2. couldn't find file 'angular' with type 'application/javascript'
这是 .bowerrc
文件:
{
"directory":"vendor/assets/bower_components"
}
这是我从 Rails 服务器控制台收到的错误:
ActionView::Template::Error (couldn't find file 'bootstrap/dist/css/bootstrap' with type 'text/css'):
2: <html>
3: <head>
4: <title>FlapperNews</title>
5: <%= stylesheet_link_tag 'application', media: 'all' %>
6: <%= javascript_include_tag 'application' %>
7: <%= csrf_meta_tags %>
8: </head>
app/assets/stylesheets/application.css:14
app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb___1398966333390810206_70171728569860'
我确认 bootstrap 和 angular 已正确安装在 Rails 应用程序中。
但它似乎在应用程序中找不到它。可能是什么问题?
最佳答案
也许您想使用 bower-rails ( https://github.com/rharriso/bower-rails ),它可以帮助您管理 Rails 应用程序中的前端依赖项。然后,您可以将依赖项添加到 Bowerfile 和 rake bower:install
,这会将您的依赖项安装到/vendor/assets/bower_components,因此现在您可以在 application.css 或 application.js 文件中要求它们.
我认为在 Rails 应用程序的根路径中有一个 bower_components 文件夹不是可行的方法,因为它的内容对 Assets 管道不可见(更多信息。在这里:http://guides.rubyonrails.org/asset_pipeline.html)
关于ruby-on-rails - Bower 在 Angular on Rails 应用程序中找不到包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36414406/