Skip to content

Commit f947b14

Browse files
authored
Merge pull request #755 from lcreid/install-docs-for-modern-rails
Explain installation for modern Rails
2 parents 83ff4d8 + 6600265 commit f947b14

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Please try to keep the checked-in `.ruby-version` set to the oldest supported ve
151151
For the record, the demo app is set up as if the Rails app had been created with:
152152

153153
```sh
154-
rails new --skip-hotwire -d sqlite --edge -j esbuild -c bootstrap .
154+
rails new -d sqlite --edge -j esbuild -c bootstrap .
155155
```
156156

157157
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.

README.md

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,25 @@ Some other nice things that `bootstrap_form` does for you are:
3131

3232
## Installation
3333

34-
Install Bootstrap 5. There are many ways to do this, depending on the asset pipeline you're using in your Rails application. One way is to use the gem that works with Sprockets. To do so, in a brand new Rails 7.0+ application created _without_ the `--webpacker` option, add the `bootstrap` gem to your `Gemfile`:
34+
This gem needs Bootstrap. The gem itself doesn't really care how Bootstrap is included in your application. There are many ways to install Bootstrap in a Rails application. Covering them all is beyond the scope of this README. However, here are some hints for a couple of common options.
3535

36-
```ruby
37-
gem "bootstrap", "~> 5.0"
36+
If you're creating a new Rails app, create it with at least the following options:
37+
38+
```bash
39+
rails new --javascript=esbuild --css=bootstrap <application-name>
3840
```
3941

40-
And follow the remaining instructions in the [official bootstrap installation guide](https://github.com/twbs/bootstrap-rubygem#a-ruby-on-rails) for setting up `application.scss` and `application.js`.
42+
`esbuild` can be any of the options, _except_ the default `importmaps`.
43+
44+
If you have an existing project, and it's processing CSS and JavaScript with some sort of front-end preprocessor, then install Bootstrap for your front-end preprocessor. That's probably something like this:
4145

42-
Add the `bootstrap_form` gem to your `Gemfile`:
46+
```bash
47+
yarn add bootstrap popper.js
48+
```
49+
50+
You can use this gem with other ways of installing Bootstrap, but how to do so is outside the scope of this README.
51+
52+
Once Bootstrap is installed, add the `bootstrap_form` gem to your `Gemfile`:
4353

4454
```ruby
4555
gem "bootstrap_form", "~> 5.4"
@@ -49,28 +59,28 @@ Then:
4959

5060
`bundle install`
5161

52-
Depending on which CSS pre-processor you are using, adding the bootstrap form styles differs slightly.
53-
If you use Rails in the default mode without any pre-processor, you'll have to add the following line to your `application.css` file:
54-
55-
```css
56-
*= require rails_bootstrap_forms
57-
```
58-
59-
If you followed the [official bootstrap installation guide](https://github.com/twbs/bootstrap-rubygem#a-ruby-on-rails), you'll probably have switched to SCSS. In this case add the following line to your `application.scss`:
60-
62+
`bootstrap_form` uses a very small number of its own CSS styles. Add the styles to your CSS bundle (usually your `application.scss` file). The way to do this depends on whether you're using Propshaft (the Rails 8 default), or Sprockets (pre-Rails 8). (Check your `Gemfile` to see whether you're using `sprockets-rails` or `propshaft`.)
6163

62-
If you're using Propshaft (for example, the Rails 8 default), do it like this:
64+
If you're using Propshaft, add the styles like this:
6365

6466
```scss
6567
@use "rails_bootstrap_forms";
6668
```
6769

68-
Else if you're using Sprockets (the Rails default before Rails 8), do it like this:
70+
If you're using Sprockets, add the styles like this:
6971

7072
```scss
7173
@import "rails_bootstrap_forms.css";
7274
```
7375

76+
If you're using Sprockets, you can also consider using the `bootstrap` gem to your `Gemfile`, as a way of installing Bootstrap itself. However, we haven't used this approach for a few years. Please report an issue if it doesn't work:
77+
78+
```ruby
79+
gem "bootstrap", "~> 5.0"
80+
```
81+
82+
And follow the remaining instructions in the [official bootstrap installation guide](https://github.com/twbs/bootstrap-rubygem#a-ruby-on-rails) for setting up `application.scss` and `application.js`.
83+
7484
## Usage
7585

7686
### bootstrap_form_for

0 commit comments

Comments
 (0)