After trying to upgrade my rails app from asset pipeline to the webpacker my modals will no longer pop up. I do not get any errors on initial load of the page or when I click on the modal button. However, if I run $('#edit').modal('show') in the console twice I get these errors:
$('#edit').modal('show')
bootstrap.esm.js:187 Uncaught TypeError: BACKDROP: Option "rootElement" provided type "null" but expected type "element".
at bootstrap.esm.js:187
at Array.forEach (<anonymous>)
at typeCheckConfig (bootstrap.esm.js:181)
at Backdrop._getConfig (bootstrap.esm.js:2856)
at new Backdrop (bootstrap.esm.js:2792)
at Modal._initializeBackDrop (bootstrap.esm.js:3117)
at new Modal (bootstrap.esm.js:2974)
at HTMLDivElement.<anonymous> (bootstrap.esm.js:3359)
at Function.each (jquery.js:328)
at jQuery.fn.init.each (jquery.js:168)
(anonymous) # bootstrap.esm.js:187
typeCheckConfig # bootstrap.esm.js:181
_getConfig # bootstrap.esm.js:2856
Backdrop # bootstrap.esm.js:2792
_initializeBackDrop # bootstrap.esm.js:3117
Modal # bootstrap.esm.js:2974
(anonymous) # bootstrap.esm.js:3359
each # jquery.js:328
each # jquery.js:168
jQueryInterface # bootstrap.esm.js:3358
(anonymous) # VM58:1
$('#edit').modal('show') ## if I enter this again I get a different error
bootstrap.esm.js:3278 Uncaught TypeError: Cannot read property 'show' of undefined
at Modal._showBackdrop (bootstrap.esm.js:3278)
at Modal.show (bootstrap.esm.js:3030)
at HTMLDivElement.<anonymous> (bootstrap.esm.js:3369)
at Function.each (jquery.js:328)
at jQuery.fn.init.each (jquery.js:168)
at jQuery.fn.init.jQueryInterface [as modal] (bootstrap.esm.js:3358)
at <anonymous>:1:12
Gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '3.0.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.3', '>= 6.1.3.2'
# Use postgresql as the database for Active Record
gem 'pg', '~> 1.1'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 5.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
gem 'bcrypt', '~> 3.1.7'
# Use jQuery as the JavaScript library
gem 'jquery-rails'
# bootstrap
gem 'bootstrap', '~> 4.5.2'
gem 'stripe', git: 'https://github.com/stripe/stripe-ruby'
# Adds Sendgrid
gem 'sendgrid-ruby'
# Adds Twilio
gem 'twilio-ruby', '~> 5.52.0'
# Adds Datatables
gem 'jquery-datatables'
# Dependency for boostrap datetimepicker
gem 'momentjs-rails', '>= 2.9.0'
# Adds DateTimePicker
gem 'bootstrap3-datetimepicker-rails', '~> 4.15.35'
# Adds input field masking
gem 'jquery_mask_rails', '~> 0.1.0'
# HTTP request gem
gem 'faraday'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false
group :development, :test do
# Debugging tools
gem 'pry'
# Testing framework
gem 'rspec-rails', '~> 5.0.0'
gem 'selenium-webdriver', '~> 3.142', '>= 3.142.7'
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 4.1.0'
# Display performance information such as SQL time and flame graphs for each request in your browser.
# Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
gem 'rack-mini-profiler', '~> 2.0'
gem 'listen', '~> 3.3'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
group :test do
# Testing frontend integration
gem 'capybara'
# Adds ability to open page during testing
gem 'launchy'
# Testing coverage
gem 'simplecov', require: false
# Disallow API calls during testing
gem 'webmock'
# Make inital API call and save as fixtures
gem 'vcr'
# Generate fixtures for testing
gem 'factory_bot_rails'
gem 'faker'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
app/javascripts/pack/application.rb
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
import Rails from "#rails/ujs"
import * as ActiveStorage from "#rails/activestorage"
import "channels"
import "datatables.net-bs4"
import "#fortawesome/fontawesome-free/css/all"
import "moment"
import "bootstrap"
import "datetimepicker"
import "jquery-mask-plugin"
Rails.start()
ActiveStorage.start()
global.$ = jQuery;
config/webpack/environment.rb
const { environment } = require('#rails/webpacker')
const webpack = require('webpack')
environment.plugins.append('Provide',
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
jquery: 'jquery',
'window.Tether': 'tether',
Popper: ['popper.js', 'default'],
ActionCable: 'actioncable',
})
)
module.exports = environment
View
<i class="fas fa-edit"></i>
<div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="Edit" aria-hidden="true" >
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Edit</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
Some form stuff
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<%= f.submit "Save", class: "btn btn-primary" %>
</div>
<% end %>
</div>
</div>
</div>
app/assets/stylesheets/application.scss
/* Load Bootstrap Libraries */
#import 'bootstrap';
/* Load Datatables */
#import "datatables";
/* Load Datetime picker */
#import 'bootstrap-datetimepicker';
Ben Trewern was right! I removed all my front-end gems from the Gemfile and added it to yarn and fixed the issue. Thanks.
Related
The following error occurred while executing the project after git clone, yarn install and bundle install.
Error logs
Sprockets::FileNotFound in Users::Sessions#new
Showing /Users/{...}/Desktop/{my_project_dir}/app/views/users/sessions/new.html.erb where line #9 raised:
couldn't find file 'angular/1.8.0/angular' with type 'application/javascript'
Checked in these paths:
/Users/{...}/{my_project_dir}/app/assets/config
/Users/{...}/{my_project_dir}/app/assets/fonts
/Users/{...}/{my_project_dir}/app/assets/images
/Users/{...}/{my_project_dir}/app/assets/javascripts
/Users/{...}/{my_project_dir}/app/assets/stylesheets
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rails_admin-2.0.2/app/assets/images
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rails_admin-2.0.2/app/assets/javascripts
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rails_admin-2.0.2/app/assets/stylesheets
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rails_admin-2.0.2/vendor/assets/fonts
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rails_admin-2.0.2/vendor/assets/images
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rails_admin-2.0.2/vendor/assets/javascripts
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rails_admin-2.0.2/vendor/assets/stylesheets
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/remotipart-1.4.4/vendor/assets/javascripts
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/nested_form-0.3.2/vendor/assets/javascripts
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/jquery-ui-rails-6.0.1/app/assets/images
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/jquery-ui-rails-6.0.1/app/assets/javascripts
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/jquery-ui-rails-6.0.1/app/assets/stylesheets
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/jquery-rails-4.4.0/vendor/assets/javascripts
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/apidoco-1.6.2/app/assets/config
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/apidoco-1.6.2/app/assets/javascripts
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/apidoco-1.6.2/app/assets/stylesheets
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/coffee-rails-4.2.2/lib/assets/javascripts
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actioncable-6.0.3.4/app/assets/javascripts
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activestorage-6.0.3.4/app/assets/javascripts
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionview-6.0.3.4/lib/assets/compiled
/Users/{...}/{my_project_dir}/node_modules):
6:
7: <div class="text-center w-75 m-auto">
8: <a href="/">
9: <span><img src="<%= image_url('bi.png') %>" alt="" height="50" /></span>
10: </a>
11: <p class="text-muted mt-3"> Title description </p><p class="text-muted"></p>
12: </div>
I don't understand why couldn't find file 'angular/1.8.0/angular' with type 'application/javascript' is happened.
Gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.7.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.2'
# Use sqlite3 as the database for Active Record
gem 'mysql2', '>= 0.4.4', '< 0.6.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
# gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
gem 'image_processing', '~> 1.2'
# Json Serializer
gem 'fast_jsonapi'
# api docs
gem 'apidoco'
# admin
gem 'rails_admin', '~> 2.0'
# control cors
gem 'rack-cors'
# pagination
gem 'kaminari'
gem 'will_paginate', '~> 3.1.0'
# api call
gem 'rest-client'
# user and admin
gem 'devise'
gem 'devise-jwt'
gem 'omniauth-oauth2'
gem 'omniauth-google-oauth2'
gem 'omniauth-naver'
gem 'devise-i18n'
# manage role
gem 'cancancan'
gem 'rolify'
# active storage
gem 'active_storage_validations'
gem 'aws-sdk-s3'
# Use ActiveStorage variant
gem 'mini_magick', '~> 4.8'
# Scheduled Job
gem 'whenever'
# Active Job
gem 'sidekiq'
gem 'connection_pool'
gem 'redis-namespace'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of chromedriver to run system tests with Chrome
gem 'chromedriver-helper'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
First of all I haven't written any angular related code within the project.
i've tried
I deleted the error code and tried again, but the same problem occurs with other erb code.
I thought maybe it could be a version of the gem files. After deleting all gems, I reinstalled ruby (using rbenv), but I got the same error.
I have installed angular#1.8.0, but I got the same error.
Please let me know solution about couldn't find file 'angular/1.8.0/angular' with type 'application/javascript'
I found problem that since multiple projects are running on one server, all the projects have to be loaded locally. In the process, there was a conflict with the apidoco gem.
Solution is to remove apidoco from the Gemfile of the problem project.
I'm running spree version 4.0.2 on Rails 6.0.2.1 and I've encountered the following error when I try to login or logout:
ActionView::Template::Error (PG::UndefinedColumn: ERROR: column spree_orders.guest_token does not exist
LINE 1: ...t" IS NULL AND "spree_orders"."currency" = $1 AND "spree_ord...
^
):
10: <ul class="nav navbar-right" data-hook>
11: <li id="link-to-cart" class="nav-item" data-hook>
12: <noscript>
13: <%= link_to_cart %>
14: </noscript>
15:
16: </li>
I know that the problem is that a query is being generated somewhere when link-to-cart is executed that refers to the column column guest_token which was changed to token in a migration. My Gemfile is shown below.
Can anyone help me with this? I'm relatively new to ruby, rails, and spree, so if I've left out important information, please let me know.
Thanks in advance!
Jeff
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.5'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.0'
# Use sqlite3 as the database for Active Record
gem 'pg'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'spree', '~> 4.0'
gem 'spree_auth_devise', '~> 4.0'
gem 'spree_gateway', '~> 3.6'
gem 'aws-sdk-s3', require: false
#gem "google-cloud-storage", "~> 1.11", require: false
gem 'spree_braintree_vzero', github: 'spree-contrib/spree_braintree_vzero'
gem 'spree_i18n', :github => 'spree/spree_i18n'
gem 'spree_globalize', github: 'spree-contrib/spree_globalize'
gem 'activerecord-nulldb-adapter'
For me it seemed to be spree_braintree_vzero gem.
Maybe it doesn't work with the latest Spree v4 ?
How to Uninstall and Remove Spree Braintree VZero
It may be useful to see what the install script is doing here:
https://github.com/spree-contrib/spree_braintree_vzero/blob/master/lib/generators/spree_braintree_vzero/install/install_generator.rb
To uninstall spree_braintree_vzero I had to do the following.
Remove the Gem from Gemfile
gem 'spree_braintree_vzero', github: 'spree-contrib/spree_braintree_vzero'
Remove all.js changes
vendor/assets/javascripts/spree/backend/all.js (git)
//= require spree/backend/spree_braintree_vzero
vendor/assets/javascripts/spree/frontend/all.js
//= require spree/frontend/spree_braintree_vzero
Delete config/schedule.rb
Yep that is all. Unless it existed before you ran the installer.
You can remove it if all it has in it is rake 'spree_braintree_vzero:update_states', otherwise remove that line from it and the surrounding blocks.
Example: https://github.com/spree-contrib/spree_braintree_vzero/blob/1bc400bb598bf177edfe614aef44fcd28eca2312/lib/generators/spree_braintree_vzero/install/install_generator.rb#L15
Add Migrations to Revert Migrations
Note: These could change so check your logs for what you did when you added it.
PS: Don't worry about migrations that touched on the spree_braintree_checkout table since it's going to be dropped.
Protip: don't forget to run your migrations ;)
class DropSpreeBraintreeCheckouts < ActiveRecord::Migration[6.0]
def up
drop_table :spree_braintree_checkouts
end
def down
raise ActiveRecord::IrreversibleMigration
end
end
class RemoveBraintreeIdFromSpreeAddresses < ActiveRecord::Migration[6.0]
def change
remove_column :spree_addresses, :braintree_id
end
end
class RemoveBraintreeTokenAndNonceFromSpreePayments < ActiveRecord::Migration[6.0]
def change
remove_column :spree_payments, :braintree_token
remove_column :spree_payments, :braintree_nonce
end
end
I am trying to implement bootstrap to my app and having issues when I try to implement some modals from bootstrap.
Created my app with using following command;
rails new HR-app -J -C --database=postgresql
My gem file
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.5'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.2', '>= 6.0.2.2'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'rspec-rails', '~> 4.0'
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'rspec-rails', '~> 4.0'
gem 'webpacker', '~> 5.1', '>= 5.1.1'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
environment.js file
const { environment } = require('#rails/webpacker')
const webpack = require('webpack')
environment.plugins.append('Provide',
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
Popper: ['popper.js', 'default']
})
)
module.exports = environment
application.scss file
#import "bootstrap/scss/bootstrap";
application.js file
import 'bootstrap'
console.log('Hello World from Webpacker')
example I took from bootstrap and index file of my scaffold;
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
And this is how it looks;
It is not desired look of modal and also it is no functional (no error). You can see the live demo of the modal here. getbootstrap.com/docs/4.0/components/modal –
How can I implement the modal as live demo from bootstrap.
Any help will be appreciated!
Thanks :)
I follow rails tutorial (https://www.railstutorial.org/book/basic_login) to generate sample rails app. But however the dropdown menu only works in development mode. In production mode, nothing happen when I click "Account". I tried below things, still cannot resolve it. Can anyone help me out?
1) pre-compile assets
2) change bootstrap and jquery order in applicaiton.js as someone mentioned
Here is _header.html.erb file code:
<header class="navbar navbar-fixed-top navbar-inverse">
<div class="container">
<%= link_to "sample app", root_path, id: "logo" %>
<nav>
<ul class="nav navbar-nav navbar-right">
<li><%= link_to "Home", home_path %></li>
<li><%= link_to "Help", help_path %></li>
<% if logged_in? %>
<li><%= link_to "Users", '#' %></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Account <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Settings", '#' %></li>
<li class="divider"></li>
<li>
<%= link_to "Log out", logout_path, method: :delete %>
</li>
</ul>
</li>
<% else %>
<li><%=link_to "Log in", login_path %></li>
<% end %>
</ul>
</nav>
</div>
</header>
Below is my assets/javascripts/application.js file:
//= require jquery
//= require bootstrap
//= require activestorage
//= require turbolinks
//= require_tree .
Here is my gem file:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.1'
# bootstrap
# gem 'bootstrap-sass'
gem 'bootstrap-sass', '~> 3.3.7'
# gem 'bootstrap', '~> 4.1.3'
# jquery
gem 'jquery-rails', '~>4.3'
# Use sqlite3 as the database for Active Record
# gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'duktape'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'sqlite3'
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of chromedriver to run system tests with Chrome
gem 'chromedriver-helper'
gem 'minitest'
gem 'minitest-reporters'
gem 'rails-controller-testing'
end
group :production do
gem 'pg'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Did you try precompiling the assets before starting your production instance? If not run:
RAILS_ENV=production rake assets:clobber
RAILS_ENV=production rake assets:precompile
Hope this helped.
I had a similiar problem with my Rails app. See here : Javascript in a fresh Rails 5.2.1 app on Heroku doesn't work properly
The problem was the uglifier gem I changed it from
gem 'uglifier', '>= 1.3.0'
which loaded the 4.1.18 version released a few weeks ago to
gem 'uglifier', '~> 3.0.4'
You should change
config.assets.debug = true
back to false because this loads all the assets one by one instead of minifying them (with uglifier's help) in production like it does in development. The error just comes from the uglifier gem not working correctly somehow
Edit:
These are my application.js require statements:
//= require jquery
//= require rails-ujs
//= require activestorage
//= require bootstrap
//= require turbolinks
//= require_tree .
This is my GemFile:
# frozen_string_literal: true
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.4.4'
gem 'coffee-rails', '~> 4.2'
gem 'jbuilder', '~> 2.5'
gem 'pg', '>= 0.18', '< 2.0'
gem 'puma', '~> 3.11'
gem 'rails', '~> 5.2.1'
gem 'sass-rails', '~> 5.0'
gem 'turbolinks', '~> 5'
gem 'uglifier', '~> 3.0.4'
gem 'bootsnap', '>= 1.1.0', require: false
gem 'bcrypt', '~> 3.1.7'
gem 'bootstrap-sass'
gem 'bootstrap-will_paginate'
gem 'faker'
gem 'friendly_id', '~> 5.2.0'
gem 'jquery-rails'
gem 'rails-i18n'
gem 'will_paginate'
group :development, :test do
gem 'byebug', platforms: %i[mri mingw x64_mingw]
end
group :development do
gem 'web-console', '>= 3.3.0'
gem 'duktape'
end
group :test do
gem 'capybara', '>= 2.15', '< 4.0'
gem 'chromedriver-helper'
gem 'rails-controller-testing'
gem 'selenium-webdriver'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
Here is the app I am working for my web development class at the moment:
Ruby on Rails Forum
I am also going with the tutorial and am at the password_reset Step of the Rails Tutorial and its working now with this set up...
Rails 5.2.1
Ruby 2.4.4p296
Windows 10 Education
Good day,
I made an app with masonry and js.coffee to make something like "pins" in my app, but when I deploy to Heroku don't work like suppose to do.
This is my gem file
source 'https://rubygems.org'
ruby '2.1.4'
gem 'binding_of_caller'
gem 'masonry-rails', '~> 0.2.0'
gem 'haml'
gem 'high_voltage', '~> 2.3.0'
gem 'activevalidators'
gem 'paperclip', github: 'thoughtbot/paperclip'
gem 'simple_form', '~>3.0.2'
gem 'acts_as_votable'
gem 'bootstrap-sass'
gem 'devise', '~> 3.4.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'
# Use sqlite3 as the database for Active Record
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :assets do
gem 'therubyracer'
gem 'less-rails'
gem 'twitter-bootstrap-rails'
gem 'libv8'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'sqlite3'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
My application.js
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require bootstrap-sprockets
//= require masonry/jquery.masonry
//= require turbolinks
//= require_tree .
My js.coffee to show pins
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
$ ->
$('#pins').imagesLoaded ->
$('#pins').masonry
itemSelector: '.box'
isFitWidth: true
My index for pins
- content_for :board do
= javascript_include_tag 'application', 'data-turbolinks-track' => true
#pins.transitions-enabled
- #pins.each do |pin|
.box.panel.panel-default
= link_to (image_tag pin.image.url), pin
%h2
= link_to pin.title, pin
%p.user
Ofertado por
= pin.user.name
%p.price
$
= pin.price
Am I doing something wrong?
If it works well under development and won't work upon deployment in heroku, you might have mistakenly configured your database.yml under config.
production:
adapter: postgresql
encoding: utf8
database: (copy database name from your heroku database info)
username: (copy username from your heroku database info)
password: TV9ncj-HR1FqNFihKm6zlsHhxU
host: (copy host from your heroku database info)
sslmode: require
and don't forget to do the rake db:migrate
if this is not the answer you were looking for, this might still be a little useful for you, if not now, maybe in the near future as you go along with your code.