Skip to content

Commit 610a5c7

Browse files
authored
Fix assets in the demo app (#678)
* Modernize config files to Rails 7 * Update demo app's binstubs * Get a new-enough node version * Ruby 3 * Git ignore new yarn version stuff * Update Gemfile to be more like Rails 7 * yarn install * Asset for jsbundling, cssbundling * Assets pipeline notes for docs * Rubocop fixes * Oops. Use defaults of Rails version under test * Need to explicitly include sprockets-rails 7.0+ * Gemfile as Sprockets says it should be
1 parent 76c2542 commit 610a5c7

37 files changed

Lines changed: 11472 additions & 7405 deletions

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ gemfiles/*.lock
1616
/.ruby-version
1717
Vagrantfile
1818
.vagrant
19-
.yarnrc
19+
**/.yarn/**/cache
20+
**/.yarn/install-state.gz
21+
**/.yarn/unplugged
2022

2123
# For the demo app.
2224

@@ -25,7 +27,7 @@ demo/storage/*
2527
!demo/storage/.keep
2628

2729
demo/public/assets
28-
.byebug_history
30+
**/.byebug_history
2931

3032
# Ignore master key for decrypting credentials and more.
3133
demo/config/master.key

.yarnrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
lastUpdateCheck 1681870014941

CONTRIBUTING.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,30 +169,40 @@ To run the demo app, set up the database and run the server:
169169
cd demo
170170
bundle
171171
rails db:setup
172-
yarn build --watch &
173-
rails s -b 0.0.0.0
172+
dev
174173
```
175174

176175
To run the demo app in the Docker container:
177176

178177
```bash
179178
docker run --volume "$PWD:/app" --user $UID:`grep ^$USERNAME /etc/passwd | cut -d: -f4` -p 3000:3000 -it bootstrap_form /bin/bash
180179
cd demo
181-
export BUNDLE_GEMFILE=../gemfiles/7.0.gemfile
180+
bundle
182181
rails db:setup
183-
yarn build --watch &
184-
rails s -b 0.0.0.0
182+
dev
185183
```
186184

187-
The app doesn't appear to find the source map, or perhaps it isn't being generated. In the Rails log you will see messages similar to:
185+
You'll see errors in the browser console about duplicate ids. This is expected, since the demo app has many forms with the same fields in them. Something we can fix in the future, perhaps.
188186

189-
```bash
190-
ActionController::RoutingError (No route matches [GET] "/assets/application.js-c6c0edbd68f05cffd0e2495198bfbc4bf42be8a11b76eecbfade30a8036b6b87.map")
187+
To use other supported versions of Rails, you will need to create a `Gemfile` for the Rails version. Then, change the `export BUNDLE_GEMFILE...` line to your gem file. Finally, figure out how to include the assets.
188+
189+
If you need to run the Rails server separately, for example, to debug the server, you _must_ run it like this:
190+
191+
```sh
192+
bundle exec rails s -b 0.0.0.0
191193
```
192194

193-
But this doesn't seem to affect how the app runs.
195+
If you run just `rails` or even `bin/rails`, the `sprockets-rails` gem won't load and you'll either get error messages, or the assets won't be available to the demo app. At the moment it's a mystery why. PRs to fix this are welcome.
194196

195-
To use other supported versions of Rails, you will need to create a `Gemfile` for the Rails version. Then, change the `export BUNDLE_GEMFILE...` line to your gem file. Finally, figure out how to include the assets.
197+
Please try to keep the checked-in `.ruby-version` set to the oldest supported version of Ruby. You're welcome and encouraged to try the demo app with other Ruby versions. Just don't check in the `.ruby-version` to GitHub.
198+
199+
For the record, the demo app is set up as if the Rails app had been created with:
200+
201+
```sh
202+
rails new --skip-hotwire -d sqlite --edge -j esbuild -c bootstrap .
203+
```
204+
205+
This means it's using `esbuild` to pre-process the JavaScript and (S)CSS, and that it's using [`jsbunding-rails`](https://github.com/rails/jsbundling-rails) and [`cssbundling-rails`](https://github.com/rails/cssbundling-rails) to put the assets in `app/assets/builds`, before the Sprockets assets pipeline serves them in development, or pre-compiles them in production.
196206

197207
## Documentation Contributions
198208

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ ENV PATH ./bin:$GEM_HOME/bin:$PATH
1313
RUN (echo 'docker'; echo 'docker') | passwd root
1414

1515
# Yarn installs nodejs.
16-
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
17-
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
18-
apt update -y -q && \
19-
apt install -y -q yarn sqlite3
16+
# Rails wants a newer version of node that we get with the Debian distro.
17+
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && apt-get install -y nodejs
18+
RUN corepack enable && corepack prepare yarn@stable --activate
19+
RUN apt install -y -q yarn sqlite3
2020

2121
EXPOSE 3000

demo/.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ruby-2.7.6
1+
ruby-3.0.5

demo/.yarnrc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
enableTelemetry: 0
2+
3+
nodeLinker: node-modules

demo/Gemfile

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
source "https://rubygems.org"
22
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
33

4-
ruby File.read("#{__dir__}/.ruby-version").delete_prefix("ruby-").chomp
5-
64
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
75
gem "rails", "~> 7.0.0"
86

97
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
10-
gem "sprockets-rails"
8+
gem "sprockets-rails", require: "sprockets/railtie"
119

1210
# Use sqlite3 as the database for Active Record
1311
gem "sqlite3", "~> 1.4"
@@ -18,12 +16,6 @@ gem "puma", "~> 5.0"
1816
# Bundle and transpile JavaScript [https://github.com/rails/jsbundling-rails]
1917
gem "jsbundling-rails"
2018

21-
# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
22-
gem "turbo-rails"
23-
24-
# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
25-
gem "stimulus-rails"
26-
2719
# Bundle and process CSS [https://github.com/rails/cssbundling-rails]
2820
gem "cssbundling-rails"
2921

@@ -45,20 +37,20 @@ gem "tzinfo-data", platforms: %i[mingw mswin x64_mingw jruby]
4537
# Reduces boot times through caching; required in config/boot.rb
4638
gem "bootsnap", require: false
4739

48-
gem "bootstrap_form", "~> 5.0"
40+
gem "bootstrap_form", path: ".."
4941

5042
# Needed for our demo app but not the gem itself
5143
gem "htmlbeautifier"
5244

5345
# Use Sass to process CSS
54-
gem "sassc-rails"
46+
# gem "sassc-rails"
5547

5648
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
5749
# gem "image_processing", "~> 1.2"
5850

5951
group :development, :test do
6052
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
61-
# gem "debug", platforms: %i[mri mingw x64_mingw]
53+
gem "debug", platforms: %i[mri mingw x64_mingw]
6254
end
6355

6456
group :development do

0 commit comments

Comments
 (0)