Rails4:如何提供gem特定的javascript文件?

时间:2014-05-10 18:07:01

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

我将一个工作的rails应用程序复制到另一个目录中,并使用重命名Gem重命名它。

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

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

我已尝试重新卸载并安装宝石

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

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

  1. 的Gemfile
  2. application.rb中
  3. application.html.haml
  4. 的application.js
  5. 有关我应该如何调试的建议吗?

    谢谢!

    为了向您展示这个问题,请在Rubymine中比较这2张图片

    工作应用程序: Working App

    非工作应用: Non-working app

    以下是一些相关文件的样子:

    的application.js enter image description here

    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
    

    的Gemfile

    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'
    

1 个答案:

答案 0 :(得分:1)

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

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

我不是百分百肯定这会解决你的问题,但我怀疑你有宝石问题。