0

Here is my code:

$('li.food').addClass('red');

Website is in production. I created a jquery file as hide.js in the app/assets/javascripts folder.

This is in my application.html.erb file:

<head>

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>

<%= javascript_include_tag 'hide', 'data-turbolinks-track' => true %>
<%= stylesheet_link_tag 'hide', media: 'all', 'data-turbolinks-track' => true %>

<%= csrf_meta_tags %>
<meta name="viewport" content="width=device-width, initial-scale=1">
<%= render 'layouts/shim' %>

</head>

This is the error message from Heroku logs:

ActionController::RoutingError (No route matches [GET] "/javascripts/hide.js"):
vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.2/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.2/lib/active_support/tagged_logging.rb:68:in `block in tagged'
vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.2/lib/active_support/tagged_logging.rb:26:in `tagged'
vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.2/lib/action_dispatch/middleware/request_id.rb:21:in `call'

This is my application.js file

//= require social-share-button
//= require jquery
//= require jquery_ujs
//= require hide
//= require hide.js
//= require bootstrap
//= require turbolinks
//= require_tree .

Gemfile

source 'https://rubygems.org'

gem 'rails',                   '4.2.2'
gem 'bootstrap-sass',          '3.2.0.0'
gem 'bcrypt',                  '3.1.7'
gem 'faker',                   '1.4.2'
gem 'carrierwave', github: 'carrierwaveuploader/carrierwave'
gem 'mini_magick',             '3.8.0'
gem 'fog',                     '1.36.0'
gem 'will_paginate',           '3.0.7'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'sass-rails',              '5.0.2'
gem 'uglifier',                '2.5.3'
gem 'coffee-rails',            '4.1.0'
gem 'jquery-rails',            '4.0.3'
gem 'turbolinks',              '2.3.0'
gem 'jbuilder',                '2.2.3'
gem 'sdoc',                    '0.4.0', group: :doc
gem 'fog-aws'
gem 'activerecord-reputation-system', require: 'reputation_system'
gem 'social-share-button', '~> 0.1.6'

group :development, :test do
  gem 'sqlite3',     '1.3.9'
  gem 'byebug',      '3.4.0'
  gem 'web-console', '2.0.0.beta3'
  gem "spring", group: :development
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', '0.0.2'
  gem 'puma',           '2.11.1'
end

Chrome Error

Failed to load resource: the server responded with a status of 404 (Not Found) ...for stylesheets/hide.css
Failed to load resource: the server responded with a status of 404 (Not Found) ...for javascripts/hide.js

I've tried bundle exec rake assets:precompile and Heroku run bundle exec rake assets:precompile.

I do not have any problem running bootstrap jquery components such as Carousel.

From searching, it seems like all I am supposed to have do is put hide.js in app/assets/javascripts and Rails is supposed to take care of the rest, :(

Timmy Von Heiss
  • 2,160
  • 17
  • 39

2 Answers2

0

remove this line from your application.js

//= require hide.js

Also if you have added hide js in your application.js file so no need to call it separate using

<%= javascript_include_tag 'hide', 'data-turbolinks-track' => true %>
Gaurav Gupta
  • 1,181
  • 10
  • 15
0

The various answers are found here.

$(document).on('page:change', function () {
// Actions to do
});
Community
  • 1
  • 1
Timmy Von Heiss
  • 2,160
  • 17
  • 39