Receiving an error (ExecJS::ProgramError in Pages#home) when I run rails server and load my page after I install bootstrap 4 ruby gem.
Completely new to Ruby on rails and largely programming so bear with me. I'm running through the One month rails tutorial (https://onemonth.com/courses/rails/curriculum) and hitting a sticking point at the installing bootstrap 4 point. I'm using windows 10 vs Mac OS for the tutorial.
I've tried running through the same directions for installing bootstrap 4 as the course uses (https://www.diycode.cc/projects/twbs/bootstrap-rubygem) as well as the latest directions (https://github.com/twbs/bootstrap-rubygem). I get the same error either way, but my latest attempt runs through the steps below.
Steps
Add bootstrap to your Gemfile:
gem 'bootstrap', '~> 4.2.1'
bundle install
Import Bootstrap styles in app/assets/stylesheets/application.scss:
// Custom bootstrap variables must be set or imported *before* bootstrap.
#import "bootstrap";
renamed application.css to application.scss in app/assets/stylesheets/
add the jquery-rails gem to your Gemfile:
gem 'jquery-rails'
bundle install
Add Bootstrap dependencies and Bootstrap to your application.js:
//= require jquery3
//= require popper
//= require bootstrap-sprockets
I've also tried removing
gem 'duktape'
from my gemfile as has been suggested elsewhere but had no luck.
Gemfile
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.3.3'
gem 'rails', '~> 5.2.2'
gem 'sqlite3'
gem 'puma', '~> 3.11'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'duktape'
gem 'coffee-rails', '~> 4.2'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
gem 'jquery-rails'
gem 'bootsnap', '>= 1.1.0', require: false
gem 'bootstrap', '~> 4.2.1'
group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
gem 'web-console', '>= 3.3.0'
end
group :test do
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
gem 'chromedriver-helper'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
application.scss
// Custom bootstrap variables must be set or imported *before* bootstrap.
#import "bootstrap";
application.js
//= require jquery3
//= require popper
//= require bootstrap-sprockets
//= require rails-ujs
//= require activestorage
//= require turbolinks
//= require_tree .
pages_controller.rb
class PagesController < ApplicationController
def home
end
end
application_controller.rb
class ApplicationController < ActionController::Base
end
home.html.erb
<h1>Welcome to my website!</h1>
<p>Sign up here</p>
<p>Teams</p>
<p>Standings</p>
<p>Schedules</p>
<p>Stats</p>
When I run rails server the page comes up saying "ExecJS::ProgramError in Pages#home"
Showing C:/omrails/app/views/layouts/application.html.erb where line #8 raised:
undefined not callable
Rails.root: C:/omrails
(execjs):1
app/views/layouts/application.html.erb:8:in `_app_views_layouts_application_html_erb__882755417_31415124'
My code in views/layouts/application.html.erb looks as follows:
<!DOCTYPE html>
<html>
<head>
<title>One Month Rails</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<%= link_to "Home", root_path %>
<%= link_to "About", about_path %>
<%= link_to "Contact us", contact_path %>
<%= yield %>
</body>
</html>
Related
I am learning to import Bootstrap in rails . When I try to run server this message appears:
Sass::SyntaxError in Home#index
Showing C:/Users/Admin/.ssh/gazalpro/app/views/layouts/application.html.erb where line #7 raised:
File to import not found or unreadable: bootstrap.
Load paths:
C:/Users/Admin/.ssh/gazalpro/app/assets/config
C:/Users/Admin/.ssh/gazalpro/app/assets/images
C:/Users/Admin/.ssh/gazalpro/app/assets/javascripts
C:/Users/Admin/.ssh/gazalpro/app/assets/stylesheets
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/coffee-rails-4.2.2/lib/assets/javascripts
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/actioncable-5.2.4.2/lib/assets/compiled
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activestorage-5.2.4.2/app/assets/javascripts
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/actionview-5.2.4.2/lib/assets/compiled
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/turbolinks-source-5.2.0/lib/assets/javascripts
C:/Users/Admin/.ssh/gazalpro/node_modules
Here is application.html.erb :
<!DOCTYPE html>
<html>
<head>
<title>Gazalpro</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<%= yield %>
</body>
</html>
Here is Gemfile :
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.5'
gem 'rails', '~> 5.2.4', '>= 5.2.4.2'
gem 'sqlite3'
gem 'puma', '~> 3.11'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'duktape'
gem 'coffee-rails', '~> 4.2'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
gem 'bootstrap', '~> 4.4', '>= 4.4.1'
gem 'jquery-rails'
# 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]
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'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Here is Application.js file :
//= require rails-ujs
//= require activestorage
//= require turbolinks
//= require jquery3
//= require popper
//= require bootstrap
//= require_tree .
Here is application.css.scss file:
#import "bootstrap";
I have already run the command 'Bundle install' and restarted the server. But I am still getting this error.
I'm a beginer in Ruby on rails and i tried to install Bootstrap but always it failed
Here is how i proceded to install it .
1)
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.6'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# 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.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'bootstrap', '~> 4.0.0.beta2.1'
gem 'sprockets-rails', '~> 3.2', '>= 3.2.1'
# 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', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
2)
#import "bootstrap";
3) In the file application.js i paste this :
//= require jquery3
//= require popper
//= require bootstrap-sprockets
//= require turbolinks
//= require_tree .
4) I got an error in the application.html.erb file so i changed "application" in the two lines to "application.scss" and "application.js" and then i installed Node.js
<!DOCTYPE html>
<html>
<head>
<title>Bali</title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application.scss', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application.js', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<%= yield %>
</body>
</html>
I did Bundle Install and reset the server. Then nothing happen to the homepage, the font didn't change...
Thank for your help
Ok now i have this, it seem that bootstrap is not displayed totaly
Bootstrap has been installed successfully you however need to create an HTML page to leverage that new CSS you have.
Run this in your terminal to make your own custom page.
rails generate controller home index
You can now update the app/views/home/index.html.erb file to contain whatever Bootstrap styled HTML you want.
The last step in order for you to view your page would be to modify the routes.rb file.
In that file, add the line root 'home#index' to see your new page when you visit your Rails app.
I am building a relatively new Rails 5 application. I've been using the bootsy gem and I've been experiencing a problem where the wysiwyg will not show on the page until after a page refresh. After playing around for a while, I discovered that if I removed turbolinks from my application.js, the wysiwyg appears first time ( without a page refresh ). Can anyone tell me how I should be requiring turbolinks into my application.js. Thanks in advance.
application.js:
//= require jquery
//= require jquery_ujs
//= require jquery.turbolinks
//= require bootstrap-sprockets
//= require bootsy
//= require turbolinks
//= require_tree .
application.scss:
#import "bootstrap-sprockets";
#import "bootstrap";
#import "bootsy";
#import "articles";
gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '5.0.0'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.15'
# 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'
gem 'jquery-turbolinks'
# 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
gem 'simple_form'
gem 'bootstrap-sass'
gem 'bootsy'
I'm using simple_form in combination with bootsy so my form looks something like this:
<%= simple_form_for #article, url: action_path do |f| %>
<%= f.input :title %>
<%= f.input :body, label: "Article Body", as: :bootsy %>
<%= f.submit %>
<% end %>
You need to use the turbolinks:load event like this :
$(document).on('turbolinks:load', ready)
function ready() {
//your code here
}
Your require is fine.
That's it.
So after a bit of playing around I found a solution. I added document.addEventListener('turbolinks:load', Bootsy.init); to my application.js and this solved the issue.
Hello everyone I have installed bootstrap for my application, and it is not working out to well. Here is my application.scss file
#import "bootstrap-sprockets";
#import "bootstrap";
Here is my application.rb file:
<!DOCTYPE html>
<html>
<head>
<title>BootstrapApp</title>
<%= stylesheet_link_tag 'default', media: 'all', 'data-turbolinks-track' => true%>
<%= javascript_include_tag 'default', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
application.js file:
// 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. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require bootstrap-sprockets
//= require turbolinks
//= require_tree .
Finally here is my Gem File:
source 'http://rubygems.org'
gem 'bootstrap-sass', '~> 3.3.5'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# 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.2'
# 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 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', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Here is what I am getting when trying to add a navbar to my webpage:
The problem is you're not requiring application.scss and application.js.
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true%>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
If you are getting the Object does not support the property or method error, then use the latest gem for "coffee-script-source" (like 1.10.0) - anything other than version 1.9.x.
Add the following line to Gemfile, run bundle install and restart the server.
gem 'coffee-script-source', '~> 1.11', '>= 1.11.1'
I finally got this to work. this link provided me with my solution. Thanks to everyone who helped me on this post, it was greatly appreciated and a great learning experience :)
I've been trying to connect bootstrap framework to my project by following this documentation and I can't set it up for some reason.
Why is it?
assets/stylesheets/application.scss
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
#import "bootstrap-sprockets";
#import "bootstrap";
*
*= require bootstrap3-editable/bootstrap-editable
*= require_tree .
*= require_self
*/
assets/javascripts/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 turbolinks
//= require bootstrap
//= require bootstrap3-editable/bootstrap-editable
//= require_tree .
views/layouts/application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Greenbull</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<div id="container">
<div id="user_header">
<% if current_user %>
Logged in as <%= current_user.full_name %>
<%= link_to "Log Out", logout_path("current"), method: 'delete' %><br />
<p><%= link_to "My tasks", user_tasks_path(current_user) %>
<% else %>
<%= link_to "Sign Up", signup_path %> or
<%= link_to 'Log In', login_path %>
<% end %>
</div>
<% flash.each do |message_type, message| %>
<div class="flash-<%= message_type %>"><%= message %></div>
<% end %>
<%= yield %>
</body>
</html>
Gemfile
source 'https://rubygems.org'
group :development, :test do
gem 'rspec-rails', '~> 3.0'
end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.3'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# 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 :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# 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'
gem 'bcrypt'
gem 'pry'
gem 'pg'
gem 'bootstrap-x-editable-rails'
gem 'bootstrap-sass'
end
I have installed bootstrap-sass 3.3.5.1, sass-rails 5.0.3.
Any help?
Read the instructions of the bootstrap-sass gem and follow their conventions https://github.com/twbs/bootstrap-sass.
Import Bootstrap styles in app/assets/stylesheets/application.scss:
// "bootstrap-sprockets" must be imported before "bootstrap" and "bootstrap/variables"
#import "bootstrap-sprockets";
#import "bootstrap";