I have found already some topics about my problem but I didnt understand how it should be fixed.
I was following http://ruby.railstutorial.org/chapters/filling-in-the-layout#fnref-5_5 tutorial and stuck by importing the bootstrap in app/assets/stylesheets/custom.css.scss.
That is my Gemfile:
source 'https://rubygems.org'
gem 'bootstrap-sass', '2.0.4'
gem 'rails', '3.2.8'
group :development, :test do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.11.0'
end
Gems used only for assets and not required
in production environments by default.
group :assets do
gem 'sass-rails', '3.2.5'
gem 'coffee-rails', '3.2.2'
gem 'uglifier', '1.2.3'
end
gem 'jquery-rails', '2.0.2'
group :test do
gem 'capybara', '1.1.2'
end
group :production do
gem 'pg', '0.12.2'
end
And what error I get on localhost/sample_app/home
Sass::SyntaxError in Static_pages#home
Showing c:/Users/katja/Arbeit/rails_projects/sample_app/app/views/layouts/application.html.erb where line #5 raised:
File to import not found or unreadable: bootstrap.
Load path: Sass::Rails::Importer(c:/Users/katja/Arbeit/rails_projects/sample_app/app/assets/stylesheets/custom.css.scss)
(in c:/Users/katja/Arbeit/rails_projects/sample_app/app/assets/stylesheets/custom.css.scss)
Extracted source (around line #5):
2:
3:
4: <%= full_title(yield(:title)) %>
5: <%= stylesheet_link_tag "application", media: "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: <!--[if lt IE 9]>
Rails.root: c:/Users/katja/Arbeit/rails_projects/sample_app
Application Trace | Framework Trace | Full Trace
app/assets/stylesheets/custom.css.scss:1
app/views/layouts/application.html.erb:5:in `app_views_layouts_application_html_erb_16020705_20168520'
I am using Windows and GitBash. I ahve already tried to delete tmp/cache, it didnt help.
Everything runs perfect but when I add #import "bootstrap"; to a cusom.css.scss, I get an error.
Restart the web server "rails s".
i had to restart the server
ps aux | grep rails
kill -9 12345
where 12345 is the process number
(not sure if there is another way to restart rails?
source 'https://rubygems.org'
gem 'rails', '3.2.8'
group :development, :test do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.11.0'
end
Gems used only for assets and not required
in production environments by default.
group :assets do
gem 'sass-rails', '3.2.5'
gem 'bootstrap-sass', '2.0.4'
gem 'coffee-rails', '3.2.2'
gem 'uglifier', '1.2.3'
end
gem 'jquery-rails', '2.0.2'
group :test do
gem 'capybara', '1.1.2'
end
group :production do
gem 'pg', '0.12.2'
end
add your bootstrap-sass gem into the assets block
Related
I've inherited a Rails app and am currently being defeated by the above error. The weird thing is this codebase is running on Heroku without this error, so I don't know how.
Here is the full error output:
ActionView::Template::Error (File to import not found or unreadable: select2.
Load paths:
/app/app/assets/javascripts
/app/app/assets/stylesheets
/app/app/assets/widget_javascripts
/usr/local/bundle/gems/coffee-rails-5.0.0/lib/assets/javascripts
/usr/local/bundle/gems/activeadmin-searchable_select-1.5.0/app/assets/javascript
/usr/local/bundle/gems/activeadmin-searchable_select-1.5.0/app/assets/stylesheets
/usr/local/bundle/gems/select2-rails-4.0.13/vendor/assets/javascripts
/usr/local/bundle/gems/select2-rails-4.0.13/vendor/assets/stylesheets
/usr/local/bundle/gems/activeadmin_quill_editor-0.3.4/app/assets/javascripts
/usr/local/bundle/gems/activeadmin_quill_editor-0.3.4/app/assets/stylesheets
/usr/local/bundle/gems/activeadmin-2.9.0/app/assets/javascripts
/usr/local/bundle/gems/activeadmin-2.9.0/app/assets/stylesheets
/usr/local/bundle/gems/activeadmin-2.9.0/vendor/assets/javascripts
/usr/local/bundle/gems/jquery-rails-4.4.0/vendor/assets/javascripts
/usr/local/bundle/gems/formtastic-4.0.0/app/assets/stylesheets
/usr/local/bundle/gems/actioncable-6.1.4.1/app/assets/javascripts
/usr/local/bundle/gems/activestorage-6.1.4.1/app/assets/javascripts
/usr/local/bundle/gems/actionview-6.1.4.1/lib/assets/compiled
/app/node_modules):
2: <html>
3: <head>
4: <title><%= yield :title_tag %></title>
5: <%= stylesheet_link_tag "application", media: "all" %>
6: <%= csrf_meta_tags %>
7: <%= csp_meta_tag %>
8: </head>
app/assets/stylesheets/active_admin.scss:5
app/views/layouts/application.html.erb:5
I, [2022-05-04T10:39:06.704054 #20] INFO -- : source=rack-timeout id=af5eb0c9-e88d-4992-9895-90fa372b4f73 timeout=15000ms service=1506ms state=completed
I've read this answer, and consequently added require references to select2 in the following files:
app/assets/stylesheets/application.css
app/assets/stylesheets/active_admin.scss
app/assets/javascripts/application.js
app/assets/javascripts/active_admin.js
...e.g. in active_admin.scss I've added
//= require select2
Someone also said the config.assets.compile setting may be relevant here. In my environment file, it's commented-out.
# config.assets.compile = false
Here's how I'm starting the app (via Docker):
gem install bundler -v 2.2.21 && bundle install && rails db:migrate && rails server --port 3000 --binding 0.0.0.0
And here's my Gemfile (there's no mention of select2 in it, but it does feature in the Gemfile.lock, most likely because it's a dependency of another Gem, namely activeadmin-searchable_select.
source 'https://rubygems.org'
ruby '2.7.5'
gem 'activeadmin', '2.9.0'
gem 'activeadmin_quill_editor'
gem 'active_reporting'
gem 'activeadmin-searchable_select'
gem 'active_admin_import'
gem 'api_guard'
gem 'apipie-rails'
gem 'azure-storage-blob', require: false
gem 'bcrypt'
gem 'blind_index'
gem 'browser'
gem 'coffee-rails'
gem 'dalli'
gem 'devise'
gem 'emoji_flag'
gem 'forecast_io'
gem 'flag_shih_tzu'
gem 'groupdate'
gem 'i18n-active_record', github: 'svenfuchs/i18n-active_record', require: 'i18n/active_record'
gem 'twilio-ruby'
gem 'feedjira'
gem 'httparty', '0.18.1'
gem 'jquery-rails'
gem 'jwt'
gem 'lockbox'
gem 'pg'
gem 'puma'
gem 'rails', '6.1.4.1'
gem 'rack-cors'
gem 'rack-timeout'
gem 'redis'
gem 'rollbar'
gem 'rqrcode'
gem 'rubyzip'
gem 'ruby-openai'
gem 'sidekiq'
gem 'sinatra', require: nil # if you require 'sinatra' you get the DSL extended to Object
gem 'slack-notifier'
gem 'slim' # slim and Sinatra are for the Sidekiq web ui
gem 'will_paginate'
group :assets do
gem 'sass-rails', '~> 5.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
gem 'mini_racer', github: 'sqreen/mini_racer', branch: 'use-libv8-node'
gem 'uglifier', '>= 1.0.3'
end
group :development do
gem 'dotenv-rails', groups: :test
gem 'launchy'
gem 'listen'
gem 'pry'
gem 'rubocop'
gem 'spring'
end
group :test do
gem 'capybara'
gem 'database_cleaner', '2.0.1'
gem 'factory_bot_rails'
gem 'ffaker'
gem 'rspec-rails', '4.0.0.rc1'
end
---- EDIT ----
active_admin.js (top of):
//= require active_admin/base
//= require active_admin/searchable_select
//= require activeadmin/quill_editor/quill
//= require activeadmin/quill_editor_input
I am trying to get the view for my project to show up. but I get this error:
ActionView::Template::Error (ReferenceError: CoffeeScript is not defined):
4: <title>Myapp</title>
5: <%= csrf_meta_tags %>
6:
7: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
8: <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
9: </head>
10:
When I remove lines 7-8 then it works, but I would have no CSS, or JavaScript.
I did not receive this error about a week ago. I'm not sure what the cause is. I tried switching Rails versions. I've tried uninstalling Postgres and setting it up again, but it does not seem to be the issue.
I have Rails 5.0.0.1, and "Ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin16]". Also I'm using Mac OS Sierra.
I could change the 'application' to 'default' and it works, but I don't understand why it worked about a week ago, and not now.
I also have my view and controller set up, which is the reason why it works when i remove lines 7-8.
This is my gem file:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.18'
# 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'
gem 'listen', '~> 3.0.5'
# 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
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
There is a problem in coffe-script-source gem 1.12.1 which was recently updated. the issue is that the source file in this version is empty. there is already an open issue , and it should be fixed soon.
For now you can add this to your GemFile
gem 'coffee-script-source', '= 1.11.1'
and run bundle update coffee-script-source until it's fixed.
I also had to use gem uninstall coffee-script-source, then gem install coffee-script-source ... as my gemfile.lock wasn't updating no matter how many times I did 'bundle install' or 'bundle update' after removing coffe-script & coffee-script-source entries in the gemfile.
I'm following Hartl's Ruby Tutorial. I'm on the beginning of chapter 5.
The instructions are to add an image ('rails.png') via
<%= link_to image_tag("rails.png", alt: "Rails logo"),
'http://rubyonrails.org/' %>
to the home page at: app/views/static_pages/home.html.erb
The image is downloaded via
$ curl -O http://rubyonrails.org/images/rails.png
$ mv rails.png app/assets/images/
However I am receiving an error on the asset precompile. I have no context on how to go about fixing this. So if there's extra info necessary to help solve this problem, let me know so I can add it!
This is the text of the error page of localhost:3000.
Sprockets::Rails::Helper::AssetNotPrecompiled in
StaticPagesController#home Asset was not declared to be precompiled
in production. Add Rails.application.config.assets.precompile += %w(
rails.png ) to config/initializers/assets.rb and restart your
server
Extracted source (around line #350): def
raise_unless_precompiled_asset(path)
raise Helper::AssetNotPrecompiled.new(path) unless precompiled?(path)
end
end
end
Edit : Gemfile
source 'https://rubygems.org'
gem 'rails', '4.2.2'
gem 'bcrypt', '3.1.7'
gem 'faker', '1.4.2'
gem 'carrierwave', '0.10.0'
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 'bootstrap-sass', '3.2.0.0'
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
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'
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
I've encountered similar issue a while ago and I've fixed it by adding .png files to precompiled assets. Just try updating your config/application.rb file with following line:
config.assets.precompile += %w(.png)
Please remember about re-starting your Rails server afterwards ;)
I'm working on a legacy Rails 3.2.8 project and when running the project I get:
ActionView::Template::Error (uninitialized constant Sass::Engine
(in /Users/sergiotapia/Documents/Work/foobar/app/assets/stylesheets/application.css.scss)):
2: <html>
3: <head>
4: <title>Foobar</title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb__1845727542545946075_70110608859600'
]
Rendered vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.7ms)
Rendered vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (7.3ms)
My Gemfile looks like this and bundle install runs without any problems. I can also migrate my database perfectly:
source 'https://rubygems.org'
gem 'rails', '3.2.8'
gem 'sqlite3'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
gem 'sass-rails', '~> 3.2.3'
# Used by Twitter Bootstrap and/or Font Awesome
gem 'therubyracer'
gem 'bootstrap-sass', '~> 2.2.2.0'
gem 'font-awesome-sass-rails'
end
gem 'jquery-rails'
gem 'devise' # Devise must be required before RailsAdmin
gem 'rails_admin', '0.4.3'
gem "cancan" # Allows us to disable Create and Delete actions for SiteSettings
gem "paperclip", "3.3.0" # Used for file uploads for ad Creatives
gem 'mysql2'
gem 'ruby-mysql'
gem 'useragent' # Allwos for easy detection of iOS devices
gem 'rmagick' # Dynamic e-carrd image generation
Why is Rails showing this error?
I also run into this issue. I resolved it by:
Taking 'sass-rails' out of the :assets group.
Manually adding the 'sass' gem: gem 'sass', '3.2.19'
I am also using 'bourbon', and in the process I had to also get it out from the :assets group and fix it to version 3.1.8.
The version of haml I am using is also 3.1.8.
Please have a try by taking the gem 'sass-rails', '~> 3.2.3' out of the group :asset block in the Gemfile.
gem 'sass-rails', '~> 3.2.3'
group :assets do
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
# Used by Twitter Bootstrap and/or Font Awesome
gem 'therubyracer'
gem 'bootstrap-sass', '~> 2.2.2.0'
gem 'font-awesome-sass-rails'
end
# Other gems
How can I get more informative error messages from SASS? It's a Rails 3.1 app that works fine in development mode, in production all I get is:
Sass::SyntaxError in Pages#home
Showing C:/documents/projects/aaa_0003/implementation/ror/aaa0003/app/views/layouts/application.html.erb where line #7 raised:
0.3 is not a color for `alpha'
(in C:/documents/projects/aaa_0003/implementation/ror/aaa0003/app/assets/stylesheets/application.css)
Extracted source (around line #7):
4: <head>
5: <title><%= title %></title>
6: <%= csrf_meta_tag %>
7: <%= stylesheet_link_tag "application" %>
8: <%= javascript_include_tag "application" %>
Gem file is:
source 'http://rubygems.org'
gem 'rails', '3.1.3'
gem 'pg', '0.11.0'
gem 'gravatar_image_tag', '1.0.0.pre2'
gem 'will_paginate'
gem 'rake'
gem "jquery-rails"
gem "nested_form"
gem 'acts-as-taggable-on'
# Gems used only for assets and not required
# in production environments by default.
gem 'sass-rails', '~> 3.1.5'
group :assets do
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
group :development do
gem 'rspec-rails', '2.5.0'
gem 'annotate', '2.4.0'
gem 'faker', '0.3.1' ## for creating loads of random users to test the site with.
end
group :production do
gem 'therubyracer-heroku'
end
Thanks.
So I ended up just manually searching through my .css.scss files and found the offending line, which indeed was trying to use a deprecated / broken css styling rule to set opacity to 0.3. All working now.