rails项目中缺少的供应商javascript文件

vendor javascript files missing from rails project

本文关键字:供应商 javascript 文件 项目 rails      更新时间:2023-09-26

我使用的是rails v4.2.4。我尝试使用命令

创建一个测试应用程序
rails new app

尽管我可以在Gemfile中看到jquery引用(也存在于application.js中),并且我也运行了bundle install,但是,vendor/assets/javascript目录是空的,不包括JS文件。我已经运行bundle install了。我应该手工添加它们,还是我错过了在Rails项目中为我拉出这些文件的命令?

app/assets/javascripts中的application.js文件

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .

jQuery.js在各自gem的vendor/assets/javascripts目录下。jquery-rails是一个所谓的Rails引擎,它本身就是一个"小应用程序"。

引擎可以被看作是为其宿主应用程序提供功能的微型应用程序。Rails应用程序实际上只是一个"增压"引擎,Rails:: application类继承了Rails:: engine的许多行为。

如何找到jquery-rails home dir

发出命令(查找jquery-rails的位置):

gem which jquery-rails
#=> /home/dimitri/.rvm/gems/ruby-2.1.5/gems/jquery-rails-4.0.5/lib/jquery-rails.rb
根据输出,

jquery-rails的主目录为:

/home/dimitri/.rvm/gems/ruby-2.1.5/gems/jquery-rails-4.0.5

您的版本和路径可能不同