简体   繁体   English

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

[英]Rails4: How to serve gem specific javascript files?

I copied a working rails app into a different directory and renamed it using the rename Gem. 我将一个工作rails应用程序复制到另一个目录中,并使用重命名Gem重命名它。

Most of the rails functionality works correct, but I am not able to serve assets bundled with gems specifically js files from bootstrap-slider-rails 大多数rails功能都正常,但我无法提供与gems捆绑的资产,特别是来自bootstrap-slider-rails的js文件

I have compared my application.rb , Gemfile and application.js and they are the same in both apps. 我比较了我的application.rb,Gemfile和application.js,它们在两个应用程序中是相同的。

I have tried uninstalling and installing the gem again 我已经尝试过再次卸载和安装gem

Simple comparison among the apps is not resolving issue. 应用程序之间的简单比较并不能解决问题。

Here are the files I have verified are same in both apps: 以下是我在两个应用中验证的文件相同:

  1. Gemfile 的Gemfile
  2. application.rb application.rb中
  3. application.html.haml application.html.haml
  4. application.js 的application.js

Any suggestions how I should debug this ? 有什么建议我应该如何调试这个?

Thanks! 谢谢!

Just to show you the issue, compare these 2 images in Rubymine 只是为了向您显示问题,请在Rubymine中比较这2张图片

Working App: 工作应用: 工作应用程序

Non working App: 非工作应用程序: 非工作应用程序

Here is how some relevant files look like: 以下是一些相关文件的外观:

application.js 的application.js 在此输入图像描述

application.rb 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 的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'

Try deleting your gemfile.lock and running bundle install again. 尝试删除gemfile.lock并再次运行bundle install。

Also refer to this SO post on copying and deploying rails apps. 也可参考 SO张贴在复制和部署Rails应用。 If you didn't, you should delete the .git file and run git init. 如果没有,则应删除.git文件并运行git init。

I'm not 100% sure this will fix your problem, but my suspicion is that you have gem issue. 我不是百分百肯定这会解决你的问题,但我怀疑你有宝石问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM