我想在我的spree扩展中添加新的javascript文件

我是铁杆新手。 我正在尝试构建Spree扩展以使用Braintree的插入式UI。 我正在尝试将新的braintree.js添加到我的扩展程序中。 这些是我到目前为止所做的步骤。

  1. /app/assets/javascripts/spree/frontend/添加到/app/assets/javascripts/spree/frontend/

  2. 添加了//= require spree/frontend/braintreeapp/assets/javascripts/spree/frontend/.js

  3. /config/initializers/创建了braintree.rb 。 该文件的内容:

     Braintree::Configuration.environment = :sandbox Braintree::Configuration.merchant_id = "merchant_id" Braintree::Configuration.public_key = "public_key" Braintree::Configuration.private_key = "private_key" 
  4. 从我的狂欢商店我运行bundle install ,这是成功的。

  5. Ran rails g :install ,它给出了以下错误:

     append vendor/assets/javascripts/spree/frontend/all.js append vendor/assets/javascripts/spree/backend/all.js insert vendor/assets/stylesheets/spree/frontend/all.css insert vendor/assets/stylesheets/spree/backend/all.css run bundle exec rake railties:install:migrations FROM=spree_hello_ext from "." Would you like to run the migrations now? [Y/n] y run bundle exec rake db:migrate from "." rake aborted! NameError: uninitialized constant Braintree /Users//Sites/spree_hello_ext/config/initializers/braintree.rb:1:in `' /Users//Sites/hellostore/config/environment.rb:5:in `' Tasks: TOP => db:migrate => environment (See full trace by running task with --trace) 

您需要在gemspec中要求braintree gem作为依赖项,然后在初始化程序尝试使用它之前需要它lib / spree_hello_ext.rb进行初始化。 类似于spree_gateway所需的spree_core: https : //github.com/spree/spree_gateway/blob/master/lib/spree_gateway.rb#L1