Bower没有在Angular on Rails应用程序中找到包

时间:2016-04-04 23:02:35

标签: ruby-on-rails angularjs ruby bower

我正在关注有关Angular on Rails(https://thinkster.io/angular-rails#jumping-in-with-angular)的Thinkster教程。 在本教程中,我按照以下方式安装前端依赖项:

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服务器时,我得到以下错误,

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'

我确认在Rails应用程序中正确安装了bootstrap和angular。 enter image description here

但似乎没有在应用中找到它。可能是什么问题?

2 个答案:

答案 0 :(得分:1)

也许您想使用bower-rails(https://github.com/rharriso/bower-rails),它可以帮助您管理Rails应用程序中的前端依赖项。然后,您可以将依赖项添加到Bowerfile和rake bower:install,这将依赖项安装到/ vendor / assets / bower_components,因此现在您可以在application.css或application.js文件中要求它们。

我认为在Rails应用程序的根路径中有一个bower_components文件夹是不可取的,因为它的内容对Asset Pipeline不可见(更多信息。这里:http://guides.rubyonrails.org/asset_pipeline.html)< / p>

答案 1 :(得分:0)

使用     config.assets.paths << Rails.root.join('vendor', 'assets', 'components') 在app.config中。

确保使用此

设置.bowerrc
{
  "directory": "vendor/assets/components"
}

也是这个问题。