Asnad Atta
Asnad Atta

Reputation: 4003

All javascripts included twice and ajax requests sent twice in Rails

I am having a hard time resolving this. I have tried almost every thing but could not solve my issue. I can see in the source view that all my javascripts are included twice. I have deleted all assets from the public folder and my application.js.coffee file is as follows:

#= require jquery
#= require pace
#= require jquery_ujs
#= require jquery-ui-1.10.3.custom.min
#= require jquery.ui.touch-punch.min
#= require bootstrap-select
#= require bootstrap-switch
#= require bootstrap-typeahead
#= require flatui-checkbox
#= require flatui-radio
#= require jquery.tagsinput
#= require jquery.placeholder
#= require turbolinks
#= require underscore
#= require backbone
#= require twitter/bootstrap
#= require bootstrap-switch
#= require flatui-checkbox
#= require share

#= require jquery.remotipart
#= require deal
window.Views = {}
window.Routers = {}

My application.rb file is:

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

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)

module Opendeals
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    config.autoload_paths += Dir["#{config.root}/lib/**/"]
    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de

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

    # Don't try to initialize the application on asset compilation.
    config.assets.initialize_on_precompile = true

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

    # Don't generate folders under app/assets for resources
    config.generators.stylesheets = false
    config.generators.javascripts = false
  end
end

and my application.html.erb layout contains the following:

<%= javascript_include_tag "https://js.stripe.com/v1/", "application" %>
<%= tag :meta, :name => "stripe-key", :content => STRIPE_PUBLIC_KEY %>
<%= stylesheet_link_tag "bootstrap", media: 'all' %>
<%= stylesheet_link_tag "flat-ui", media: 'all' %>
<%= stylesheet_link_tag "custom", media: "all" %>
<%= stylesheet_link_tag "animate", media: "all" %>

All ajax requests are submitting twice.

Upvotes: 1

Views: 364

Answers (1)

Asnad Atta
Asnad Atta

Reputation: 4003

I am posting answer just for others there are some partials in my application which were added by other developer. I explore all the partials and I found this in a partial.

<%= javascript_include_tag :application %>

I removed it and my application start working as expected. This means we were including application.js twice. I just removed this line and every thing is resolved.

Upvotes: 1

Related Questions