Upgrade Bootstrap in Rails 7 app with esbuild - ruby-on-rails

Gemfile
ruby '3.1.2'
gem 'rails', '~> 7.0'
gem 'pg' , '~> 1.4.3'
gem "jsbundling-rails"
gem "sprockets-rails"
gem "turbo-rails"
➜ yarn upgrade bootstrap
Results in:
├─ bootstrap#4.6.2
package.json is the similar "bootstrap": "^4.5.0",
How do I upgrade to Bootstrap 5?
Although app/assets/builds/application.css has * Bootstrap v5.2.1
Trying to sort out asset pipeline in Rails 7 while trying to sort out problems with Leaflet.

Change package.json to "bootstrap": "^5.2.1", and then run
yarn install
yarn upgrade
yarn add and yarn remove updates package.json.
yarn outdated is helpful too, but I haven't followed through on understanding the dependencies and pitfalls.

Related

Installing a Ruby Gem on a Dockerized Application

I want to install awesome_print in my dockerized ruby application. Running
docker-compose run application_name gem install awesome_print
says "Successfully installed awesome_print-1.8.0," however, it does not appear in my Gemfile even after running
docker-compose run application_name bundle install
How can I install awesome_print in my dockerized application?
The RubyGems gem command is actually a much older package manager that predates bundler.
Running gem install foo just installs the gem to your local repository (a folder somewhere). It does not add the gem to your Gemfile and it does not perform the dependency tree resolution that Bundler does to ensure that your gems are actually compatible.
Bundler is built on top of gem. To install gems with bundler (which is what you pretty much always want to do) you add the gem to your Gemfile and run bundle install.
gem 'awesome_print', '~> 1.8'
Bundler also has a bundle add command which will add a gem to the Gemfile and install your bundle, for example:
bundle add awesome_print --version "~> 1.8"

Could not find gem 'canvas_connect (= 0.3.12 )' in any of the gem sources listed in your Gemfile or available on this machine

When run bundle install getting this error https://i.stack.imgur.com/V4O3U.png
In Gemfile
gem 'canvas_connect', '0.3.12'
gem 'adobe_connect', '1.0.6', require: false
Canvas Connect Check this link for the available versions, the version mentioned in your Gemfile is wrong. Either update it with the version which you want to just remove it. Bundle will install the latest available .
adobe_connect is a dependent gem and recheck the version mentioned with available versions.
Rubygems.org should be used as reference to compare and find gem versions
Try installing these gems
gem 'canvas_connect', '~> 0.3.11'
and
gem 'adobe_connect', '~> 1.0', '>= 1.0.6', require: false
It seems like 0.3.11 is the latest version for canvas_connect.

Ruby on Rails migrate error after add these 3 gems in my gemfile

After adding these 3 gems:
gem 'carrierwave', '0.10.0'
gem 'mini_magick', '3.8.0'
gem 'fog', '1.26.0'
And then I did bundle exec rake db:migrate, I got:
Add this to your Gemfile: gem 'net-ssh' and run bundle install after that. Looks like the particular version of fog you are using is missing the dependency. This is a known bug that has already been fixed in successive versions of the gem.

angular-simple-format bower dependencies different from rails-assets dependencies

In my Gemfile I'm using rails-assets to load angular and a number of other bower packages:
gem 'rails-assets-angular', '~> 1.3.5'
#... others
gem 'rails-assets-angular-simple-format', '~> 0.9.2'
angular-simple-format seems to be happy with any version of angular and any version of angular-sanitize:
"dependencies": {
"angular": "*",
"angular-sanitize": "*"
}
Why does bundle update --source rails-assets-angular-simple-format give me this error:
Bundler could not find compatible versions for gem "rails-assets-angular":
In Gemfile:
rails-assets-angular-simple-format (~> 0.9.2) ruby depends on
rails-assets-angular (= 1.2.21) ruby
rails-assets-angular (1.3.5)
Is there another layer of dependency management that rails-assets imposes between the bower package and bundler? How do I see what it is?
Although angular-simple-format accepts any version of angular or angular-sanitize, if you check the dependencies for angular-sanitize it requires angular 1.21 which is causing a conflict.
You would have to force rails-assets-angular to version 1.2.21 on the first line of your Gemfile.
It turns out that rails-assets does mess with dependencies. The rails-assets-angular-simple-format gem specifies the version of angularjs more strictly than the original bower project. From rails-assets-angular-simple-format.gemspec:
spec.add_dependency "rails-assets-angular", "1.2.21"
To solve I copied the original bower project into vendor/assets/javascripts and removed the rails-assets gem from the Gemfile.

rails connect to database

I'm trying to open by my rails console in my newsly created app, but I can't connect to a database. It looks like there might be a problem with sqlite3-1.3.3 vs 1.3.4
$ rails c
/Library/Ruby/Gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:71:in `establish_connection': Please install the sqlite3 adapter: `gem install activerecord-sqlite3-adapter` (can't activate sqlite3 (~> 1.3.4, runtime), already activated sqlite3-1.3.3. Make sure all dependencies are added to Gemfile.) (RuntimeError)
Install
$sudo gem install
ERROR: could not find gem activerecord-sqlite3-adapter locally or in a repository
What gems I have installed
$gem list
*** LOCAL GEMS ***
...
sqlite3 (1.3.3)
sqlite3-ruby (1.3.3, 1.3.2, 1.2.5)
I'm using rails 3.1.1
EDIT:
Here is my gemfile
source 'http://rubygems.org'
gem 'rails', '3.1.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
gem 'json'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
Running bundle install produces this
$sudo bundle install
using rake (0.9.2.2)
...
Using sqlite3 (1.3.3)
Your bundle is complete! Use bundle show [gemname] to see where a bundled gem is installed.
$ bundle show sqlite3
/Library/Ruby/Gems/1.8/gems/sqlite3-1.3.3
You're using Rails 3.1, which uses bundler to manage gems.
Add gem 'sqlite3' to your Gemfile
run bundle form the command line
This will install the gems your app needs. You should then be able to launch the console.
I've seen similar situations in the past because of missing/bad shared libraries. Gems install ruby code, native bindings to libraries, but they do not install the external libraries themselves.
The dependency for sqlite on Ubuntu, for example, is libsqlite3-dev.
$ sudo apt-get install libsqlite3-dev
For OSX:
Install sqlite3 on mac osx?

Resources