Jquery不在Production& Heroku但在开发中运作良好

时间:2016-04-27 11:06:27

标签: javascript jquery ruby-on-rails heroku

你的建议将不胜感激。

  

Heroku和我的生产环境没有拿起我的jQuery   编码(Javascript文件) - 我确实尝试了每个代码,建议和命令   并且仍然不成功。我已经粘贴了下面的文件 - 如果可以的话   指出我做错了什么需要纠正的   非常欣赏它。

-

  

视图/布局/ application.html.erb

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <title><%= full_title(yield(:title)) %></title>

    <%= stylesheet_link_tag    "application" %>
    <%= javascript_include_tag "vendor/modernizr" %>

    <%= csrf_meta_tags %>
    <%= favicon_link_tag 'img-logo-five.png' %>
    <%= favicon_link_tag 'apple-touch-icon-#{196}x#{196}.png', rel: 'apple-touch-icon', type:'image/png' %>
  </head>

  <body data-no-turbolink="true">
    <div class="medium-12 columns container"> 

      <% if notice %>
        <div id="notice_wrapper">
          <p id="notice"><%= notice %></p>
        </div>
      <% elsif alert %>
        <div id="alert_wrapper">
          <p id="alert"><%= alert %></p> 
        </div>
      <% end %>

      <%= yield %>
    </div>

    <%= javascript_include_tag "application" %>
  </body>
</html>
  

的Gemfile

source 'https://rubygems.org'

gem 'rails', '4.1.10'
gem 'bcrypt', '3.1.7'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0',          group: :doc
gem 'foundation-rails', '5.3.1.0'
gem 'simple_form'
gem "font-awesome-rails"
gem 'devise'
gem "ransack", github: "activerecord-hackery/ransack", branch: "rails-4.1"
gem "polyamorous", :github => "activerecord-hackery/polyamorous"
gem 'carrierwave'
gem 'rmagick'
gem 'acts_as_commentable'
gem "cocoon"
gem 'geocoder'
gem 'social-share-button'
gem 'twilio-ruby'
gem 'cancancan', '~> 1.10'
gem 'public_activity'
gem 'foundation-datetimepicker-rails'
gem 'jquery-ui-rails'

group :development, :test do
  gem 'sqlite3',     '1.3.9'
  gem 'byebug',      '3.4.0'
  gem 'web-console', '2.0.0.beta3'
  gem 'spring',      '1.1.3'
  gem 'quiet_assets'
  gem 'mailcatcher'
  gem "better_errors"
  gem 'awesome_print'
  gem 'pry'
  gem 'binding_of_caller'
end

group :test do
  gem 'minitest-reporters', '1.0.5'
  gem 'mini_backtrace',     '0.1.3'
  gem 'guard-minitest',     '2.3.1'
end

group :production do
  gem 'pg',             '0.17.1'
  gem 'rails_12factor'
  gem 'unicorn',        '4.8.3'
end
  

配置/环境/ production.rb

Rails.application.configure do
  config.cache_classes = true
  config.eager_load = true
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.serve_static_files = true
  config.assets.compress = true
  config.assets.js_compressor = :uglifier
  config.assets.compile = true
  config.assets.precompile =  ['*.js', '*.css', '*.css.erb']
  config.assets.digest = true
  config.log_level = :info
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
  config.log_formatter = ::Logger::Formatter.new
  config.active_record.dump_schema_after_migration = false
  config.action_mailer.default_url_options = { host: 'website.herokuapp.com' }
  Rails.application.routes.default_url_options[:host] = 'website.herokuapp.com'
end
  

配置/区域设置/ application.rb中

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

require 'rails/all'
Bundler.require(*Rails.groups)

module RecruitmentAfricaApp
  class Application < Rails::Application
    config.assets.precompile += %w(*.js)
    config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    config.autoload_paths += Dir[Rails.root.join('app', 'models', '{**}')]
    config.action_mailer.delivery_method = :smtp
    config.action_mailer.smtp_settings = {
       address: "smtp.mandrillapp.com", #if using a another domain this will be provided by the domain company
       port: 111,
       enable_starttls_auto: true,
       user_name: "email@gmail.com", #this would need to be for example info@recruitmentafrica.com
       password: "#####",
       authentication: :login,
       domain: "gmail.com",
     }
  end
end
  

资产/ Javascript角/ application.js中

    //= require jquery
//= require jquery_ujs
//= require foundation
//= require turbolinks
//= require jquery-ui
//= require cocoon
//= require social-share-button
//= require foundation-datetimepicker
//= require_tree .


/*=========================================
    general js content
  =========================================*/

$(function(){ $(document).foundation(); });


// sigin-in alert message | devise signin/signout error messages
$(document).ready(function(){
  setTimeout(function(){
    $('#notice_wrapper').fadeOut("slow", function() {
      $(this).remove();
    })
  }, 2500);
});

// sigin-out alert message | devise signin/signout error messages
$(document).ready(function(){
  setTimeout(function(){
    $('#alert_wrapper').fadeOut("slow", function() {
      $(this).remove();
    })
  }, 2500);
});

// jquery-ui datepicker 
$(document).ready(function() {
  $('.datepicker').datepicker({ dateFormat: 'MM dd, yy' }); 
  // $('.datepicker').datepicker({ dateFormat: 'D, dd M yy' }); 
});
  

资产/样式表/ application.css

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 *= require_tree .
 *= require_self
 *= require foundation_and_overrides
 *= require foundation
 *= require social-share-button
 *= require jquery-ui
 *= require font-awesome
 */
  

命令&amp;我尝试但仍然没有成功的代码

  • [1。] i have re-arranged my js files in application.js
  • [2.]我已在production.rb中设置:config.assets.compile = true
  • [3。]我运行了命令:rake assets:precompile然后git push heroku master
  • [4。]我已经运行了命令:RAILS_ENV=production bundle exec rake assets:precompile
  • [5。]我运行了命令:heroku run rake assets:precompile --app appName
  • [6。]我的javascript不会返回404 HTTP error在线
  • [7。]我尝试在gemfile gem 'jquery-turbolinks'&amp;中添加gem。在application.js //= require jquery.turbolinks
  • 中 application.rb中的
  • [8。]我添加了:config.assets.precompile += %w(*.js)
  • 生产中的
  • [9。]。我添加了config.assets.precompile = ['*.js', '*.css', '*.css.erb']
  • [10。]我将一个简单的警报代码alert('some-unique-string')放入heroku,但没有在控制台中看到警报
  • [11。]我已经设置:assets.compress=true
  • [12。]我已设置:config.assets.compress = true&amp;运行命令RAILS_ENV=production bundle exec rake assets:precompile
  • [14。]我安装了jquery.migrate.plugin 我不确定该怎么办&amp;非常感谢你的帮助。非常感谢

1 个答案:

答案 0 :(得分:-1)

在部署到heroku之前我需要预编译我的文件:

  • bundle exec rake assets:precompile
  • git add .
  • git commit -m "precompiled files"
  • git push heroku master

这会自动将所有js文件和css文件更新到heroku