【问题标题】:Rails4: How to serve gem specific javascript files?Rails4:如何提供特定于 gem 的 javascript 文件?
【发布时间】:2014-06-28 08:56:57
【问题描述】:

我将一个正常工作的 Rails 应用程序复制到了不同的目录中,并使用重命名 Gem 对其进行了重命名。

大多数 rails 功能都可以正常工作,但我无法提供与 gems 捆绑的资产,特别是来自 bootstrap-slider-rails 的 js 文件

我比较了我的 application.rb 、 Gemfile 和 application.js ,它们在两个应用程序中是相同的。

我已尝试再次卸载和安装 gem

应用之间的简单比较并不能解决问题。

以下是我验证的两个应用程序中相同的文件:

  1. 宝石文件
  2. application.rb
  3. application.html.haml
  4. application.js

有什么建议我应该如何调试?

谢谢!

只是为了向您展示问题,在 Rubymine 中比较这 2 个图像

工作应用程序:

不工作的应用程序:

以下是一些相关文件的外观:

application.js

application.rb

require File.expand_path('../boot', __FILE__)

# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"

#if defined?(Bundler)
#  # If you precompile assets before deploying to production, use this line
#  #Bundler.require(*Rails.groups(:assets => %w(development test)))
#  # If you want your assets lazily compiled in production, use this line
#  # Bundler.require(:default, :assets, Rails.env)
#end

# Rails4
Bundler.require(:default, Rails.env)

module Smoothlyhired
  class Application < Rails::Application

    # don't generate RSpec tests for views and helpers
    config.generators do |g|

      g.test_framework :rspec, fixture: true
      g.fixture_replacement :factory_girl, dir: 'spec/factories'


      g.view_specs false
      g.helper_specs false
    end


    config.autoload_paths += %W(#{config.root}/lib)



    config.encoding = "utf-8"

    # Configure sensitive parameters which will be filtered from the log file.
    config.filter_parameters += [:password, :password_confirmation]


    config.active_record.schema_format = :sql



    # Enable the asset pipeline
    config.assets.enabled = true

    # Version of your assets, change this if you want to expire all your assets
    config.assets.version = '1.0'

    #Prevent initializing the application and connecting to db on bootup as required by heroku
    #https://devcenter.heroku.com/articles/rails-asset-pipeline
    # Not required on rails4 anymore
    #config.assets.initialize_on_precompile = false

    #config.action_view.javascript_expansions[:defaults] = %w(jquery.min jquery_ujs)
  end
end

宝石文件

source 'https://rubygems.org'
ruby '2.1.0'
gem 'rails', '4.0.0'
gem 'sass-rails', '~> 4.0.0'
gem 'coffee-rails', git: 'git://github.com/rails/coffee-rails.git'
gem 'uglifier', '>= 1.0.3'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'font-awesome-sass'
gem 'less-rails'
gem 'therubyracer', :platform=>:ruby
gem 'twitter-bootstrap-rails'
#gem 'jquery_mobile_rails'
gem 'js-routes'
gem 'cancan'
gem 'devise'
gem 'figaro'
gem 'haml-rails'
gem 'pg'
gem 'rolify'
gem 'sendgrid'
gem 'simple_form'
gem 'thin'
gem 'rake'

#To use db for storing cookies instead cookie-store
gem 'activerecord-session_store', github: 'rails/activerecord-session_store'

group :development do
  gem 'better_errors'
  #gem 'binding_of_caller', :platforms=>[:mri_19, :rbx]
  #Commenting out platforms part, because may be that's stopping this to be used on the dev machine'
  gem 'binding_of_caller'
  gem 'guard-bundler'
  gem 'guard-rails'
  gem 'guard-rspec'
  gem 'html2haml'
  gem 'quiet_assets'
  gem 'rb-fchange', :require=>false
  gem 'rb-fsevent', :require=>false
  gem 'rb-inotify', :require=>false

  # Required with Rails panel chrome extension. This Gem should come after better_errors gem
  gem 'meta_request'
end
group :development, :test do
  #gem 'factory_girl_rails'
  #gem 'rspec-rails'
  gem 'pry-byebug'
  gem 'pry-stack_explorer'
  gem 'pry-rails'
  gem 'pry-debugger'
  gem 'debugger', '>= 1.6.5'
end

group :test do
  gem 'capybara'
  gem 'database_cleaner'
  gem 'email_spec'
end

group :production do
  gem 'rails_12factor'
end

gem 'high_voltage'

#Linkedin Logins
gem "linkedin"
gem "omniauth"
gem "omniauth-linkedin"

gem "omniauth-facebook"

#postgres use hstore in active record
#gem 'activerecord-postgres-hstore'

gem 'state_machine'
gem "ruby-graphviz"


#payments
#gem 'stripe',:git => 'https://github.com/stripe/stripe-ruby'


#gem 'newrelic_rpm'

gem 'pgbackups-archive'

gem 'pg_search'

gem 'acts-as-taggable-on'

#gem 'activeadmin' , github: 'gregbell/active_admin'
gem "activeadmin", git: "https://github.com/gregbell/active_admin"

#gem 'kaminari'
gem 'bootstrap-slider-rails'

#gem 'twitter_bootstrap_form_for'
#gem 'bootstrap_form'
#gem 'formtastic'
gem 'formtastic-bootstrap'
gem 'rename'

【问题讨论】:

    标签: ruby-on-rails twitter-bootstrap ruby-on-rails-4 asset-pipeline


    【解决方案1】:

    尝试删除您的 gemfile.lock 并再次运行 bundle install。

    另请参阅this SO 关于复制和部署 Rails 应用程序的帖子。如果没有,您应该删除 .git 文件并运行 git init。

    我不是 100% 确定这会解决您的问题,但我怀疑您遇到了 gem 问题。

    【讨论】:

    • 谢谢蔡斯。我剥离了更多的宝石并重新捆绑。然而,这并没有帮助。另外,请注意图像中的库,如 jquery,jquery_ujs 也没有通过 application.js 加载
    • 有趣。会不会和activeadmin有冲突?还有另一个关于that的SO帖子。
    • 还有一个用于 Rails 的 Chrome 扩展 [调试] (developers.google.com/chrome-developer-tools/docs/…) 你似乎也在使用已弃用的 gem 'anjlab-bootstrap-rails' 所以你有 2 个引导 gem,这可能会导致问题。您还有 formtastic 和 formtastic-bootstrap ,它们的作用基本相同。
    • 感谢 Chase 跟进 cmets。这些是我取出的确切宝石。还尝试在没有帮助的情况下删除活动管理员。更令人困惑的是,prev 应用程序具有相同的 gem 文件,并且滑块等在旧应用程序的机器上仍然可以正常工作
    • 没问题。我很想找到解决方案,似乎它可能很有趣。也许宝石版本不同?或者你可以使用 javascript_include_tag 来调试它?
    猜你喜欢
    • 2012-06-07
    • 1970-01-01
    • 1970-01-01
    • 2014-10-21
    • 1970-01-01
    • 2011-09-07
    • 1970-01-01
    • 1970-01-01
    • 2011-09-01
    相关资源
    最近更新 更多