[英]Installing bower and rails
我正在嘗試在Rails 4應用程序中設置Bower,特別是我正在嘗試安裝語音元素 Web組件:http: //zenorocha.github.io/voice-elements/
我曾經考慮過使用涼亭式圍欄,但希望將其保持在盡可能的香草狀態,但是我有點迷茫。 到目前為止,我已經按照以下步驟操作:
在rails根中創建.bowerrc
{
"directory": "vendor/assets/bower_components"
}
添加到application.rb
config.assets.paths << Rails.root.join('vendor', 'assets', 'bower_components')
從鐵軌根
bower init
從供應商/資產
bower install --save voice-elements
Rails 顯示視圖中的示例代碼
<voice-player id="mi-elemento" accent="es-ES" text="Me gusta la gasolina"></voice-player>
<script>
var form = document.querySelector('#mi-form'),
element = document.querySelector('#mi-elemento');
form.addEventListener('submit', function(e) {
e.preventDefault();
element.speak();
});
</script>
我不確定從這里去哪里。 如何告訴Rails如何在供應商/資產中使用語音元素庫?
作為替代方案:您會考慮使用rails-assets.org
嗎? 無需安裝Bower,您可以將Bower軟件包作為常規gem安裝。
您可以在Gemfile
的頂部添加以下行:
source 'https://rubygems.org'
source 'https://rails-assets.org'
然后為您的包裹添加一行,gem為calles rails-assets-<package-name>
,因此在您的情況下
gem 'rails-assets-voice-elements'
您可以使用非常漂亮的gem
將Bower
與Rails
集成: bower-rails
。 嘗試這種方式。
您是否按照“使用”說明進行語音元素? 看來您需要包括一些Bower創建的javascript(您應該能夠在application.js
要求它),然后在布局中添加指向兩個HTML文件的<link>
標簽。
嘗試將其添加到application.js
:
//= require platform/platform
然后將這些行添加到布局中的<head>
部分:
<link rel="import" href="<%= asset_path 'voice-elements/dist/voice-player.html' %>">
<link rel="import" href="<%= asset_path 'voice-elements/dist/voice-recognition.html' %>">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.