Skip to content

Commit 06ba02d

Browse files
ihabadhamclaude
andcommitted
Improve tutorial: extract Heroku deployment, fix versions, reorganize structure
Changes to tutorial.md: 1. Replaced Heroku deployment section (139 lines) with brief Deployment section linking to deployment guides 2. Updated versions: Ruby 2.7 → 3.0+, Rails 5.1.3 → 7.0+, RoR v13 → v16 3. Clarified Redux usage: tutorial demonstrates Redux, but basic installer uses Hooks (user choice) 4. Merged duplicate HMR sections into one cohesive section using ./bin/dev 5. Renamed "Other features" → "Going Further" with better organization: - Server Rendering (important) - Optional Configuration subsection (/client structure, Cloud9, RubyMine) Changes to heroku-deployment.md: 1. Merged tutorial's detailed Heroku instructions with existing guide 2. Added note about older versions with link to current Heroku Rails 7 guide 3. Organized into clear sections: Create App, Buildpacks, Postgres, Puma, Node/Yarn, Assets, Deploy Rationale: - Tutorial was overwhelming with platform-specific deployment before core features - Heroku content now in dedicated guide (reusable, maintainable) - Clear separation: tutorial teaches React on Rails, deployment guides teach platforms - Better progression: install → run → features → deploy → advanced 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 7af1af4 commit 06ba02d

File tree

2 files changed

+175
-164
lines changed

2 files changed

+175
-164
lines changed

docs/deployment/heroku-deployment.md

Lines changed: 140 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
# Heroku Deployment
22

3+
> **Note:** This guide is based on the working tutorial app at [reactrails.com](https://reactrails.com). While the instructions work, some versions referenced are older. For current Heroku best practices with Rails 7, see [Heroku's Rails 7 Guide](https://devcenter.heroku.com/articles/getting-started-with-rails7).
4+
5+
## Create Your Heroku App
6+
7+
_Assuming you can log in to heroku.com and have logged into your shell for Heroku._
8+
9+
1. Visit [https://dashboard.heroku.com/new](https://dashboard.heroku.com/new) and create an app, say named `my-name-react-on-rails`:
10+
11+
![06](https://cloud.githubusercontent.com/assets/20628911/17465014/1f29bf3c-5cf4-11e6-869f-4215987ae854.png)
12+
13+
Run this command that looks like this from your new Heroku app
14+
15+
```bash
16+
heroku git:remote -a my-name-react-on-rails
17+
```
18+
319
## Heroku buildpacks
420

521
React on Rails requires both a ruby environment (for Rails) and a Node environment (for Webpack), so you will need to have Heroku use multiple buildpacks.
622

7-
Assuming you have downloaded and installed the Heroku command-line utility and have initialized the app, you will need to tell Heroku to use both buildpacks via the command-line:
23+
Set heroku to use multiple buildpacks:
824

925
```bash
1026
heroku buildpacks:set heroku/ruby
@@ -13,6 +29,129 @@ heroku buildpacks:add --index 1 heroku/nodejs
1329

1430
For more information, see [Using Multiple Buildpacks for an App](https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app)
1531

32+
## Swap out sqlite for postgres
33+
34+
Heroku requires your app to use Postgresql. If you have not set up your app
35+
with Postgresql, you need to change your app settings to use this database.
36+
37+
Run the following command (in Rails 6+):
38+
39+
```bash
40+
rails db:system:change --to=postgresql
41+
```
42+
43+
If for any reason you want to do this process manually, run these two commands:
44+
45+
```bash
46+
bundle remove sqlite3
47+
bundle add pg
48+
```
49+
50+
![07](https://cloud.githubusercontent.com/assets/20628911/17465015/1f2f4042-5cf4-11e6-8287-2fb077550809.png)
51+
52+
Now replace your `database.yml` file with this (assuming your app name is "ror").
53+
54+
```yml
55+
default: &default
56+
adapter: postgresql
57+
username:
58+
password:
59+
host: localhost
60+
61+
development:
62+
<<: *default
63+
database: ror_development
64+
65+
# Warning: The database defined as "test" will be erased and
66+
# re-generated from your development database when you run "rake".
67+
# Do not set this db to the same as development or production.
68+
test:
69+
<<: *default
70+
database: ror_test
71+
72+
production:
73+
<<: *default
74+
database: ror_production
75+
```
76+
77+
Then you need to set up Postgres so you can run locally:
78+
79+
```bash
80+
rake db:setup
81+
rake db:migrate
82+
```
83+
84+
![08](https://cloud.githubusercontent.com/assets/20628911/17465016/1f3559f0-5cf4-11e6-8ab4-c5572e4644a5.png)
85+
86+
Optionally you can add this line to your `routes.rb`. That way, your root page will go to the Hello World page for React On Rails.
87+
88+
```ruby
89+
root "hello_world#index"
90+
```
91+
92+
![09](https://cloud.githubusercontent.com/assets/20628911/17465018/1f3b685e-5cf4-11e6-93f8-105fc48517d0.png)
93+
94+
## Configure Puma
95+
96+
Next, configure your app for Puma, per the [instructions on Heroku](https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server).
97+
98+
Create `./Procfile` with the following content. This is what Heroku uses to start your app.
99+
100+
```
101+
web: bundle exec puma -C config/puma.rb
102+
```
103+
104+
Note, newer versions of Rails create this file automatically. However, the [docs on Heroku](https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#config) have something a bit different, so please make it conform to those docs. As of 2020-06-04, the docs looked like this:
105+
106+
`config/puma.rb`
107+
108+
```rb
109+
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
110+
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
111+
threads threads_count, threads_count
112+
113+
preload_app!
114+
115+
rackup DefaultRackup
116+
port ENV['PORT'] || 3000
117+
environment ENV['RACK_ENV'] || 'development'
118+
119+
on_worker_boot do
120+
# Worker specific setup for Rails 4.1+
121+
# See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
122+
ActiveRecord::Base.establish_connection
123+
end
124+
```
125+
126+
## Specify Node and Yarn versions
127+
128+
Next, update your `package.json` to specify the version of yarn and node. Add this section:
129+
130+
```json
131+
"engines": {
132+
"node": "16.19.0",
133+
"yarn": "1.22.4"
134+
},
135+
```
136+
137+
## Deploy
138+
139+
Then after all changes are done don't forget to commit them with git and finally, you can push your app to Heroku!
140+
141+
```bash
142+
git add -A
143+
git commit -m "Changes for Heroku"
144+
git push heroku master
145+
```
146+
147+
Then run:
148+
149+
```bash
150+
heroku open
151+
```
152+
153+
and you will see your live app and you can share this URL with your friends. Congrats!
154+
16155
## assets:precompile
17156

18157
### Shakapacker Webpack configuration

0 commit comments

Comments
 (0)