├── .eslintrc.js
├── .gitattributes
├── .gitignore
├── .rubocop.yml
├── .ruby-version
├── Gemfile
├── Gemfile.lock
├── Procfile.dev
├── README.md
├── Rakefile
├── app
├── assets
│ ├── builds
│ │ └── .keep
│ ├── config
│ │ └── manifest.js
│ ├── images
│ │ └── .keep
│ └── stylesheets
│ │ └── .keep
├── channels
│ └── application_cable
│ │ ├── channel.rb
│ │ └── connection.rb
├── controllers
│ ├── api
│ │ └── events_controller.rb
│ ├── application_controller.rb
│ ├── concerns
│ │ └── .keep
│ └── site_controller.rb
├── helpers
│ ├── application_helper.rb
│ └── site_helper.rb
├── javascript
│ ├── application.js
│ ├── components
│ │ ├── App.css
│ │ ├── App.js
│ │ ├── Editor.js
│ │ ├── Event.js
│ │ ├── EventForm.js
│ │ ├── EventList.js
│ │ ├── EventNotFound.js
│ │ └── Header.js
│ ├── controllers
│ │ ├── application.js
│ │ ├── hello_controller.js
│ │ └── index.js
│ └── helpers
│ │ ├── helpers.js
│ │ └── notifications.js
├── jobs
│ └── application_job.rb
├── mailers
│ └── application_mailer.rb
├── models
│ ├── application_record.rb
│ ├── concerns
│ │ └── .keep
│ └── event.rb
└── views
│ ├── layouts
│ ├── application.html.erb
│ ├── mailer.html.erb
│ └── mailer.text.erb
│ └── site
│ └── index.html.erb
├── bin
├── bundle
├── dev
├── rails
├── rake
└── setup
├── config.ru
├── config
├── application.rb
├── boot.rb
├── cable.yml
├── credentials.yml.enc
├── database.yml
├── environment.rb
├── environments
│ ├── development.rb
│ ├── production.rb
│ └── test.rb
├── initializers
│ ├── assets.rb
│ ├── content_security_policy.rb
│ ├── filter_parameter_logging.rb
│ ├── inflections.rb
│ └── permissions_policy.rb
├── locales
│ └── en.yml
├── puma.rb
├── routes.rb
└── storage.yml
├── db
├── migrate
│ └── 20220313134908_create_events.rb
├── schema.rb
├── seeds.rb
└── seeds
│ └── events.json
├── lib
├── assets
│ └── .keep
└── tasks
│ └── .keep
├── log
└── .keep
├── package-lock.json
├── package.json
├── public
├── 404.html
├── 422.html
├── 500.html
├── apple-touch-icon-precomposed.png
├── apple-touch-icon.png
├── favicon.ico
└── robots.txt
├── storage
└── .keep
├── test
├── application_system_test_case.rb
├── channels
│ └── application_cable
│ │ └── connection_test.rb
├── controllers
│ ├── .keep
│ └── site_controller_test.rb
├── fixtures
│ ├── events.yml
│ └── files
│ │ └── .keep
├── helpers
│ └── .keep
├── integration
│ └── .keep
├── mailers
│ └── .keep
├── models
│ ├── .keep
│ └── event_test.rb
├── system
│ └── .keep
└── test_helper.rb
├── tmp
├── .keep
├── pids
│ └── .keep
└── storage
│ └── .keep
└── vendor
└── .keep
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | root: true,
3 | extends: ['airbnb', 'airbnb/hooks', 'prettier'],
4 | rules: {
5 | 'react/jsx-filename-extension': [1, { extensions: ['.js', '.jsx'] }],
6 | 'react/function-component-definition': [
7 | 1,
8 | { namedComponents: 'arrow-function' },
9 | ],
10 | 'no-console': 0,
11 | 'no-alert': 0,
12 | },
13 | };
14 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # See https://git-scm.com/docs/gitattributes for more about git attribute files.
2 |
3 | # Mark the database schema as having been generated.
4 | db/schema.rb linguist-generated
5 |
6 | # Mark any vendored files as having been vendored.
7 | vendor/* linguist-vendored
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2 | #
3 | # If you find yourself ignoring temporary files generated by your text editor
4 | # or operating system, you probably want to add a global ignore instead:
5 | # git config --global core.excludesfile '~/.gitignore_global'
6 |
7 | # Ignore bundler config.
8 | /.bundle
9 |
10 | # Ignore the default SQLite database.
11 | /db/*.sqlite3
12 | /db/*.sqlite3-*
13 |
14 | # Ignore all logfiles and tempfiles.
15 | /log/*
16 | /tmp/*
17 | !/log/.keep
18 | !/tmp/.keep
19 |
20 | # Ignore pidfiles, but keep the directory.
21 | /tmp/pids/*
22 | !/tmp/pids/
23 | !/tmp/pids/.keep
24 |
25 | # Ignore uploaded files in development.
26 | /storage/*
27 | !/storage/.keep
28 | /tmp/storage/*
29 | !/tmp/storage/
30 | !/tmp/storage/.keep
31 |
32 | /public/assets
33 |
34 | # Ignore master key for decrypting credentials and more.
35 | /config/master.key
36 |
37 | /app/assets/builds/*
38 | !/app/assets/builds/.keep
39 |
40 | /node_modules
41 |
--------------------------------------------------------------------------------
/.rubocop.yml:
--------------------------------------------------------------------------------
1 | require: rubocop-rails
2 |
3 | AllCops:
4 | DisplayCopNames: true
5 | DisplayStyleGuide: true
6 | ExtraDetails: true
7 | TargetRubyVersion: 3.1
8 | Exclude:
9 | - bin/**/*
10 | - config/environments/**/*
11 | - config/initializers/**/*
12 | - config/application.rb
13 | - config/boot.rb
14 | - config/environment.rb
15 | - config/puma.rb
16 | - db/migrate/**/*
17 | - db/schema.rb
18 |
19 | Layout/LineLength:
20 | Max: 120
21 |
22 | Rails:
23 | Enabled: true
24 |
25 | Style/Documentation:
26 | Enabled: false
27 |
28 | Style/ClassAndModuleChildren:
29 | Enabled: false
30 |
--------------------------------------------------------------------------------
/.ruby-version:
--------------------------------------------------------------------------------
1 | 3.1.0
2 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | source 'https://rubygems.org'
4 | git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5 |
6 | ruby '3.1.0'
7 |
8 | # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
9 | gem 'rails', '~> 7.0.2', '>= 7.0.2.3'
10 |
11 | # The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
12 | gem 'sprockets-rails'
13 |
14 | # Use sqlite3 as the database for Active Record
15 | gem 'sqlite3', '~> 1.4'
16 |
17 | # Use the Puma web server [https://github.com/puma/puma]
18 | gem 'puma', '~> 5.0'
19 |
20 | # Bundle and transpile JavaScript [https://github.com/rails/jsbundling-rails]
21 | gem 'jsbundling-rails'
22 |
23 | # Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
24 | gem 'turbo-rails'
25 |
26 | # Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
27 | gem 'stimulus-rails'
28 |
29 | # Build JSON APIs with ease [https://github.com/rails/jbuilder]
30 | gem 'jbuilder'
31 |
32 | # Use Redis adapter to run Action Cable in production
33 | # gem "redis", "~> 4.0"
34 |
35 | # Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
36 | # gem "kredis"
37 |
38 | # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
39 | # gem "bcrypt", "~> 3.1.7"
40 |
41 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
42 | gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
43 |
44 | # Reduces boot times through caching; required in config/boot.rb
45 | gem 'bootsnap', require: false
46 |
47 | # Use Sass to process CSS
48 | # gem "sassc-rails"
49 |
50 | # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
51 | # gem "image_processing", "~> 1.2"
52 |
53 | group :development, :test do
54 | # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
55 | gem 'debug', platforms: %i[mri mingw x64_mingw]
56 | end
57 |
58 | group :development do
59 | # Use console on exceptions pages [https://github.com/rails/web-console]
60 | gem 'web-console'
61 |
62 | # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
63 | # gem "rack-mini-profiler"
64 |
65 | # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
66 | # gem "spring"
67 | end
68 |
69 | group :test do
70 | # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
71 | gem 'capybara'
72 | gem 'selenium-webdriver'
73 | gem 'webdrivers'
74 | end
75 |
--------------------------------------------------------------------------------
/Gemfile.lock:
--------------------------------------------------------------------------------
1 | GEM
2 | remote: https://rubygems.org/
3 | specs:
4 | actioncable (7.0.2.3)
5 | actionpack (= 7.0.2.3)
6 | activesupport (= 7.0.2.3)
7 | nio4r (~> 2.0)
8 | websocket-driver (>= 0.6.1)
9 | actionmailbox (7.0.2.3)
10 | actionpack (= 7.0.2.3)
11 | activejob (= 7.0.2.3)
12 | activerecord (= 7.0.2.3)
13 | activestorage (= 7.0.2.3)
14 | activesupport (= 7.0.2.3)
15 | mail (>= 2.7.1)
16 | net-imap
17 | net-pop
18 | net-smtp
19 | actionmailer (7.0.2.3)
20 | actionpack (= 7.0.2.3)
21 | actionview (= 7.0.2.3)
22 | activejob (= 7.0.2.3)
23 | activesupport (= 7.0.2.3)
24 | mail (~> 2.5, >= 2.5.4)
25 | net-imap
26 | net-pop
27 | net-smtp
28 | rails-dom-testing (~> 2.0)
29 | actionpack (7.0.2.3)
30 | actionview (= 7.0.2.3)
31 | activesupport (= 7.0.2.3)
32 | rack (~> 2.0, >= 2.2.0)
33 | rack-test (>= 0.6.3)
34 | rails-dom-testing (~> 2.0)
35 | rails-html-sanitizer (~> 1.0, >= 1.2.0)
36 | actiontext (7.0.2.3)
37 | actionpack (= 7.0.2.3)
38 | activerecord (= 7.0.2.3)
39 | activestorage (= 7.0.2.3)
40 | activesupport (= 7.0.2.3)
41 | globalid (>= 0.6.0)
42 | nokogiri (>= 1.8.5)
43 | actionview (7.0.2.3)
44 | activesupport (= 7.0.2.3)
45 | builder (~> 3.1)
46 | erubi (~> 1.4)
47 | rails-dom-testing (~> 2.0)
48 | rails-html-sanitizer (~> 1.1, >= 1.2.0)
49 | activejob (7.0.2.3)
50 | activesupport (= 7.0.2.3)
51 | globalid (>= 0.3.6)
52 | activemodel (7.0.2.3)
53 | activesupport (= 7.0.2.3)
54 | activerecord (7.0.2.3)
55 | activemodel (= 7.0.2.3)
56 | activesupport (= 7.0.2.3)
57 | activestorage (7.0.2.3)
58 | actionpack (= 7.0.2.3)
59 | activejob (= 7.0.2.3)
60 | activerecord (= 7.0.2.3)
61 | activesupport (= 7.0.2.3)
62 | marcel (~> 1.0)
63 | mini_mime (>= 1.1.0)
64 | activesupport (7.0.2.3)
65 | concurrent-ruby (~> 1.0, >= 1.0.2)
66 | i18n (>= 1.6, < 2)
67 | minitest (>= 5.1)
68 | tzinfo (~> 2.0)
69 | addressable (2.8.0)
70 | public_suffix (>= 2.0.2, < 5.0)
71 | bindex (0.8.1)
72 | bootsnap (1.11.1)
73 | msgpack (~> 1.2)
74 | builder (3.2.4)
75 | capybara (3.36.0)
76 | addressable
77 | matrix
78 | mini_mime (>= 0.1.3)
79 | nokogiri (~> 1.8)
80 | rack (>= 1.6.0)
81 | rack-test (>= 0.6.3)
82 | regexp_parser (>= 1.5, < 3.0)
83 | xpath (~> 3.2)
84 | childprocess (4.1.0)
85 | concurrent-ruby (1.1.9)
86 | crass (1.0.6)
87 | debug (1.4.0)
88 | irb (>= 1.3.6)
89 | reline (>= 0.2.7)
90 | digest (3.1.0)
91 | erubi (1.10.0)
92 | globalid (1.0.0)
93 | activesupport (>= 5.0)
94 | i18n (1.10.0)
95 | concurrent-ruby (~> 1.0)
96 | io-console (0.5.11)
97 | io-wait (0.2.1)
98 | irb (1.4.1)
99 | reline (>= 0.3.0)
100 | jbuilder (2.11.5)
101 | actionview (>= 5.0.0)
102 | activesupport (>= 5.0.0)
103 | jsbundling-rails (1.0.2)
104 | railties (>= 6.0.0)
105 | loofah (2.14.0)
106 | crass (~> 1.0.2)
107 | nokogiri (>= 1.5.9)
108 | mail (2.7.1)
109 | mini_mime (>= 0.1.1)
110 | marcel (1.0.2)
111 | matrix (0.4.2)
112 | method_source (1.0.0)
113 | mini_mime (1.1.2)
114 | minitest (5.15.0)
115 | msgpack (1.4.5)
116 | net-imap (0.2.3)
117 | digest
118 | net-protocol
119 | strscan
120 | net-pop (0.1.1)
121 | digest
122 | net-protocol
123 | timeout
124 | net-protocol (0.1.2)
125 | io-wait
126 | timeout
127 | net-smtp (0.3.1)
128 | digest
129 | net-protocol
130 | timeout
131 | nio4r (2.5.8)
132 | nokogiri (1.13.3-x86_64-linux)
133 | racc (~> 1.4)
134 | public_suffix (4.0.6)
135 | puma (5.6.2)
136 | nio4r (~> 2.0)
137 | racc (1.6.0)
138 | rack (2.2.3)
139 | rack-test (1.1.0)
140 | rack (>= 1.0, < 3)
141 | rails (7.0.2.3)
142 | actioncable (= 7.0.2.3)
143 | actionmailbox (= 7.0.2.3)
144 | actionmailer (= 7.0.2.3)
145 | actionpack (= 7.0.2.3)
146 | actiontext (= 7.0.2.3)
147 | actionview (= 7.0.2.3)
148 | activejob (= 7.0.2.3)
149 | activemodel (= 7.0.2.3)
150 | activerecord (= 7.0.2.3)
151 | activestorage (= 7.0.2.3)
152 | activesupport (= 7.0.2.3)
153 | bundler (>= 1.15.0)
154 | railties (= 7.0.2.3)
155 | rails-dom-testing (2.0.3)
156 | activesupport (>= 4.2.0)
157 | nokogiri (>= 1.6)
158 | rails-html-sanitizer (1.4.2)
159 | loofah (~> 2.3)
160 | railties (7.0.2.3)
161 | actionpack (= 7.0.2.3)
162 | activesupport (= 7.0.2.3)
163 | method_source
164 | rake (>= 12.2)
165 | thor (~> 1.0)
166 | zeitwerk (~> 2.5)
167 | rake (13.0.6)
168 | regexp_parser (2.2.1)
169 | reline (0.3.1)
170 | io-console (~> 0.5)
171 | rexml (3.2.5)
172 | rubyzip (2.3.2)
173 | selenium-webdriver (4.1.0)
174 | childprocess (>= 0.5, < 5.0)
175 | rexml (~> 3.2, >= 3.2.5)
176 | rubyzip (>= 1.2.2)
177 | sprockets (4.0.3)
178 | concurrent-ruby (~> 1.0)
179 | rack (> 1, < 3)
180 | sprockets-rails (3.4.2)
181 | actionpack (>= 5.2)
182 | activesupport (>= 5.2)
183 | sprockets (>= 3.0.0)
184 | sqlite3 (1.4.2)
185 | stimulus-rails (1.0.4)
186 | railties (>= 6.0.0)
187 | strscan (3.0.1)
188 | thor (1.2.1)
189 | timeout (0.2.0)
190 | turbo-rails (1.0.1)
191 | actionpack (>= 6.0.0)
192 | railties (>= 6.0.0)
193 | tzinfo (2.0.4)
194 | concurrent-ruby (~> 1.0)
195 | web-console (4.2.0)
196 | actionview (>= 6.0.0)
197 | activemodel (>= 6.0.0)
198 | bindex (>= 0.4.0)
199 | railties (>= 6.0.0)
200 | webdrivers (5.0.0)
201 | nokogiri (~> 1.6)
202 | rubyzip (>= 1.3.0)
203 | selenium-webdriver (~> 4.0)
204 | websocket-driver (0.7.5)
205 | websocket-extensions (>= 0.1.0)
206 | websocket-extensions (0.1.5)
207 | xpath (3.2.0)
208 | nokogiri (~> 1.8)
209 | zeitwerk (2.5.4)
210 |
211 | PLATFORMS
212 | x86_64-linux
213 |
214 | DEPENDENCIES
215 | bootsnap
216 | capybara
217 | debug
218 | jbuilder
219 | jsbundling-rails
220 | puma (~> 5.0)
221 | rails (~> 7.0.2, >= 7.0.2.3)
222 | selenium-webdriver
223 | sprockets-rails
224 | sqlite3 (~> 1.4)
225 | stimulus-rails
226 | turbo-rails
227 | tzinfo-data
228 | web-console
229 | webdrivers
230 |
231 | RUBY VERSION
232 | ruby 3.1.0p0
233 |
234 | BUNDLED WITH
235 | 2.3.3
236 |
--------------------------------------------------------------------------------
/Procfile.dev:
--------------------------------------------------------------------------------
1 | web: bin/rails server -p 3000
2 | js: npm run watch
3 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Creating a Simple CRUD App with Rails and React
2 |
3 | This is the code repository to accompany a tutorial on how to create a Rails API then, using esbuild, build a React front-end to consume it.
4 |
5 | Tutorial URL: [https://hibbard.eu/rails-react-crud-app/](https://hibbard.eu/rails-react-crud-app/)
6 |
7 | **This is the code for the updated version of the tutorial. You can find the code for the older version on the [classes branch](https://github.com/jameshibbard/react-rails-crud-app/tree/classes)**
8 |
9 | ## Requirements
10 |
11 | - [Ruby](https://www.ruby-lang.org/en/downloads/)
12 | - [Node.js](http://nodejs.org/)
13 |
14 | There are instructions for installing both Ruby and Node at the beginning of the tutorial.
15 |
16 | ## Installation
17 |
18 | - Clone repo
19 | - Run `bundle install`
20 | - Run `npm install`
21 | - Run `rake db:create`, `rake db:migrate`, then `rake db:seed`
22 |
23 | ## Running
24 |
25 | - Start the Rails server and esbuild with one command `./bin/dev`
26 | - Hit http://localhost:3000/events/
27 |
28 | ## License
29 |
30 | Code archives and code examples are licensed under the MIT license.
31 |
32 | Copyright © 2022 James Hibbard
33 |
34 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
35 |
36 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
37 |
38 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Add your own tasks in files placed in lib/tasks ending in .rake,
4 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
5 |
6 | require_relative 'config/application'
7 |
8 | Rails.application.load_tasks
9 |
--------------------------------------------------------------------------------
/app/assets/builds/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/app/assets/builds/.keep
--------------------------------------------------------------------------------
/app/assets/config/manifest.js:
--------------------------------------------------------------------------------
1 | //= link_tree ../images
2 | //= link_directory ../stylesheets .css
3 | //= link_tree ../builds
4 |
--------------------------------------------------------------------------------
/app/assets/images/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/app/assets/images/.keep
--------------------------------------------------------------------------------
/app/assets/stylesheets/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/app/assets/stylesheets/.keep
--------------------------------------------------------------------------------
/app/channels/application_cable/channel.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module ApplicationCable
4 | class Channel < ActionCable::Channel::Base
5 | end
6 | end
7 |
--------------------------------------------------------------------------------
/app/channels/application_cable/connection.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module ApplicationCable
4 | class Connection < ActionCable::Connection::Base
5 | end
6 | end
7 |
--------------------------------------------------------------------------------
/app/controllers/api/events_controller.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class Api::EventsController < ApplicationController
4 | before_action :set_event, only: %i[show update destroy]
5 |
6 | def index
7 | @events = Event.all
8 | render json: @events
9 | end
10 |
11 | def show
12 | render json: @event
13 | end
14 |
15 | def create
16 | @event = Event.new(event_params)
17 |
18 | if @event.save
19 | render json: @event, status: :created
20 | else
21 | render json: @event.errors, status: :unprocessable_entity
22 | end
23 | end
24 |
25 | def update
26 | if @event.update(event_params)
27 | render json: @event, status: :ok
28 | else
29 | render json: @event.errors, status: :unprocessable_entity
30 | end
31 | end
32 |
33 | def destroy
34 | @event.destroy
35 | end
36 |
37 | private
38 |
39 | def set_event
40 | @event = Event.find(params[:id])
41 | end
42 |
43 | def event_params
44 | params.require(:event).permit(
45 | :id, :event_type, :event_date, :title, :speaker, :host, :published, :created_at, :updated_at
46 | )
47 | end
48 | end
49 |
--------------------------------------------------------------------------------
/app/controllers/application_controller.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class ApplicationController < ActionController::Base
4 | protect_from_forgery with: :null_session
5 | end
6 |
--------------------------------------------------------------------------------
/app/controllers/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/app/controllers/concerns/.keep
--------------------------------------------------------------------------------
/app/controllers/site_controller.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class SiteController < ApplicationController
4 | def index; end
5 | end
6 |
--------------------------------------------------------------------------------
/app/helpers/application_helper.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module ApplicationHelper
4 | end
5 |
--------------------------------------------------------------------------------
/app/helpers/site_helper.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module SiteHelper
4 | end
5 |
--------------------------------------------------------------------------------
/app/javascript/application.js:
--------------------------------------------------------------------------------
1 | /* global document */
2 |
3 | // Entry point for the build script in your package.json
4 | import '@hotwired/turbo-rails';
5 | import './controllers';
6 |
7 | import React, { StrictMode } from 'react';
8 | import { createRoot } from 'react-dom/client';
9 | import { BrowserRouter } from 'react-router-dom';
10 | import App from './components/App';
11 |
12 | const container = document.getElementById('root');
13 | const root = createRoot(container);
14 |
15 | document.addEventListener('DOMContentLoaded', () => {
16 | root.render(
17 |
18 |
19 |
20 |
21 |
22 | );
23 | });
24 |
--------------------------------------------------------------------------------
/app/javascript/components/App.css:
--------------------------------------------------------------------------------
1 | body, html, div, blockquote, img, label, p, h1, h2, h3, h4, h5, h6, pre, ul, ol, li, dl, dt, dd, form, a, fieldset, input, th, td {
2 | margin: 0;
3 | padding: 0;
4 | }
5 |
6 | ul, ol {
7 | list-style: none;
8 | }
9 |
10 | body {
11 | font-family: Roboto;
12 | font-size: 16px;
13 | line-height: 28px;
14 | }
15 |
16 | header {
17 | background: #f57011;
18 | height: 60px;
19 | }
20 |
21 | header h1, header h1 a{
22 | display: inline-block;
23 | font-family: "Maven Pro";
24 | font-size: 28px;
25 | font-weight: 500;
26 | color: white;
27 | padding: 14px 5%;
28 | text-decoration: none;
29 | }
30 |
31 | header h1:hover {
32 | text-decoration: underline;
33 | }
34 |
35 | .grid {
36 | display: grid;
37 | grid-gap: 50px;
38 | grid-template-columns: minmax(250px, 20%) auto;
39 | margin: 25px auto;
40 | width: 90%;
41 | height: calc(100vh - 145px);
42 | }
43 |
44 | .eventList {
45 | background: #f6f6f6;
46 | padding: 16px;
47 | }
48 |
49 | .eventList h2 {
50 | font-size: 20px;
51 | padding: 8px 6px 10px;
52 | }
53 |
54 | .eventContainer {
55 | font-size: 15px;
56 | line-height: 35px;
57 | }
58 |
59 | .eventContainer h2 {
60 | margin-bottom: 10px;
61 | }
62 |
63 | .eventList li:hover, a.active {
64 | background: #f8e5ce;
65 | }
66 |
67 | .eventList a {
68 | display: block;
69 | color: black;
70 | text-decoration: none;
71 | border-bottom: 1px solid #dddddd;
72 | padding: 8px 6px 10px;
73 | }
74 |
75 | .eventList h2 > a {
76 | color: #236fff;
77 | font-size: 15px;
78 | float: right;
79 | font-weight: normal;
80 | border-bottom: none;
81 | padding: 0px;
82 | }
83 |
84 | .eventForm {
85 | margin-top: 15px;
86 | }
87 |
88 | label > strong {
89 | display: inline-block;
90 | vertical-align: top;
91 | text-align: right;
92 | width: 100px;
93 | margin-right: 6px;
94 | font-size: 15px;
95 | }
96 |
97 | input, textarea {
98 | padding: 2px 0 3px 3px;
99 | width: 400px;
100 | margin-bottom: 15px;
101 | box-sizing: border-box;
102 | }
103 |
104 | input[type="checkbox"] {
105 | width: 13px;
106 | }
107 |
108 | button[type="submit"] {
109 | background: #f57011;
110 | border: none;
111 | padding: 5px 25px 8px;
112 | font-weight: 500;
113 | color: white;
114 | cursor: pointer;
115 | margin: 10px 0 0 106px;
116 | }
117 |
118 | .errors {
119 | border: 1px solid red;
120 | border-radius: 5px;
121 | margin: 20px 0 35px 0;
122 | width: 513px;
123 | }
124 |
125 | .errors h3 {
126 | background: red;
127 | color: white;
128 | padding: 10px;
129 | font-size: 15px;
130 | }
131 |
132 | .errors ul li {
133 | list-style-type: none;
134 | margin: 0;
135 | padding: 8px 0 8px 10px;
136 | border-top: solid 1px pink;
137 | font-size: 12px;
138 | font-weight: 0.9;
139 | }
140 |
141 | button.delete {
142 | background: none !important;
143 | border: none;
144 | padding: 0 !important;
145 | margin-left: 10px;
146 | cursor: pointer;
147 | color: #236fff;
148 | font-size: 15px;
149 | font-weight: normal;
150 | text-decoration: none;
151 | }
152 |
153 | button.delete:hover {
154 | text-decoration: underline;
155 | }
156 |
157 | h2 a {
158 | color: #236fff;
159 | font-size: 15px;
160 | font-weight: normal;
161 | margin: 3px 12px 0 12px;
162 | text-decoration: none;
163 | }
164 |
165 | h2 a:hover {
166 | text-decoration: underline;
167 | }
168 |
169 | .form-actions a {
170 | color: #236fff;
171 | font-size: 15px;
172 | margin: 3px 12px 0 12px;
173 | text-decoration: none;
174 | }
175 |
176 | .form-actions a:hover {
177 | text-decoration: underline;
178 | }
179 |
180 | input.search {
181 | width: 92%;
182 | margin: 15px 2px;
183 | padding: 4px 0 6px 6px;
184 | }
185 |
186 | .loading {
187 | height: calc(100vh - 60px);
188 | display: grid;
189 | justify-content: center;
190 | align-content: center;
191 | }
192 |
--------------------------------------------------------------------------------
/app/javascript/components/App.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Routes, Route } from 'react-router-dom';
3 | import { ToastContainer } from 'react-toastify';
4 | import Editor from './Editor';
5 | import './App.css';
6 |
7 | const App = () => (
8 | <>
9 |
10 | } />
11 |
12 |
13 | >
14 | );
15 |
16 | export default App;
17 |
--------------------------------------------------------------------------------
/app/javascript/components/Editor.js:
--------------------------------------------------------------------------------
1 | /* global window */
2 |
3 | import React, { useState, useEffect } from 'react';
4 | import { Routes, Route, useNavigate } from 'react-router-dom';
5 | import Header from './Header';
6 | import Event from './Event';
7 | import EventForm from './EventForm';
8 | import EventList from './EventList';
9 | import { success } from '../helpers/notifications';
10 | import { handleAjaxError } from '../helpers/helpers';
11 |
12 | const Editor = () => {
13 | const [events, setEvents] = useState([]);
14 | const [isLoading, setIsLoading] = useState(true);
15 | const navigate = useNavigate();
16 |
17 | useEffect(() => {
18 | const fetchData = async () => {
19 | try {
20 | const response = await window.fetch('/api/events.json');
21 | if (!response.ok) throw Error(response.statusText);
22 |
23 | const data = await response.json();
24 | setEvents(data);
25 | } catch (error) {
26 | handleAjaxError(error);
27 | }
28 |
29 | setIsLoading(false);
30 | };
31 |
32 | fetchData();
33 | }, []);
34 |
35 | const addEvent = async (newEvent) => {
36 | try {
37 | const response = await window.fetch('/api/events.json', {
38 | method: 'POST',
39 | body: JSON.stringify(newEvent),
40 | headers: {
41 | Accept: 'application/json',
42 | 'Content-Type': 'application/json',
43 | },
44 | });
45 |
46 | if (!response.ok) throw Error(response.statusText);
47 |
48 | const savedEvent = await response.json();
49 | const newEvents = [...events, savedEvent];
50 | setEvents(newEvents);
51 | success('Event Added!');
52 | navigate(`/events/${savedEvent.id}`);
53 | } catch (error) {
54 | handleAjaxError(error);
55 | }
56 | };
57 |
58 | const deleteEvent = async (eventId) => {
59 | const sure = window.confirm('Are you sure?');
60 |
61 | if (sure) {
62 | try {
63 | const response = await window.fetch(`/api/events/${eventId}.json`, {
64 | method: 'DELETE',
65 | });
66 |
67 | if (!response.ok) throw Error(response.statusText);
68 |
69 | success('Event Deleted!');
70 | navigate('/events');
71 | setEvents(events.filter(event => event.id !== eventId));
72 | } catch (error) {
73 | handleAjaxError(error);
74 | }
75 | }
76 | };
77 |
78 | const updateEvent = async (updatedEvent) => {
79 | try {
80 | const response = await window.fetch(
81 | `/api/events/${updatedEvent.id}.json`,
82 | {
83 | method: 'PUT',
84 | body: JSON.stringify(updatedEvent),
85 | headers: {
86 | Accept: 'application/json',
87 | 'Content-Type': 'application/json',
88 | },
89 | }
90 | );
91 |
92 | if (!response.ok) throw Error(response.statusText);
93 |
94 | const newEvents = events;
95 | const idx = newEvents.findIndex((event) => event.id === updatedEvent.id);
96 | newEvents[idx] = updatedEvent;
97 | setEvents(newEvents);
98 |
99 | success('Event Updated!');
100 | navigate(`/events/${updatedEvent.id}`);
101 | } catch (error) {
102 | handleAjaxError(error);
103 | }
104 | };
105 |
106 | return (
107 | <>
108 |
109 | {isLoading ? (
110 |
Loading...
111 | ) : (
112 |
113 |
114 |
115 |
116 | }
119 | />
120 | }
123 | />
124 | } />
125 |
126 |
127 | )}
128 | >
129 | );
130 | };
131 |
132 | export default Editor;
133 |
--------------------------------------------------------------------------------
/app/javascript/components/Event.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import PropTypes from 'prop-types';
3 | import { useParams, Link } from 'react-router-dom';
4 | import EventNotFound from './EventNotFound';
5 |
6 | const Event = ({ events, onDelete }) => {
7 | const { id } = useParams();
8 | const event = events.find((e) => e.id === Number(id));
9 |
10 | if (!event) return ;
11 |
12 | return (
13 |
14 |
15 | {event.event_date}
16 | {' - '}
17 | {event.event_type}
18 | Edit
19 |
26 |
27 |
28 | -
29 | Type: {event.event_type}
30 |
31 | -
32 | Date: {event.event_date}
33 |
34 | -
35 | Title: {event.title}
36 |
37 | -
38 | Speaker: {event.speaker}
39 |
40 | -
41 | Host: {event.host}
42 |
43 | -
44 | Published: {event.published ? 'yes' : 'no'}
45 |
46 |
47 |
48 | );
49 | };
50 |
51 | Event.propTypes = {
52 | events: PropTypes.arrayOf(
53 | PropTypes.shape({
54 | id: PropTypes.number.isRequired,
55 | event_type: PropTypes.string.isRequired,
56 | event_date: PropTypes.string.isRequired,
57 | title: PropTypes.string.isRequired,
58 | speaker: PropTypes.string.isRequired,
59 | host: PropTypes.string.isRequired,
60 | published: PropTypes.bool.isRequired,
61 | })
62 | ).isRequired,
63 | onDelete: PropTypes.func.isRequired,
64 | };
65 |
66 | export default Event;
67 |
--------------------------------------------------------------------------------
/app/javascript/components/EventForm.js:
--------------------------------------------------------------------------------
1 | import React, { useCallback, useEffect, useState, useRef } from 'react';
2 | import { useParams, Link } from 'react-router-dom';
3 | import Pikaday from 'pikaday';
4 | import PropTypes from 'prop-types';
5 | import EventNotFound from './EventNotFound';
6 | import { formatDate, isEmptyObject, validateEvent } from '../helpers/helpers';
7 |
8 | import 'pikaday/css/pikaday.css';
9 |
10 | const EventForm = ({ events, onSave }) => {
11 | const { id } = useParams();
12 |
13 | const initialEventState = useCallback(
14 | () => {
15 | const defaults = {
16 | event_type: '',
17 | event_date: '',
18 | title: '',
19 | speaker: '',
20 | host: '',
21 | published: false,
22 | };
23 | const currEvent = id ? events.find((e) => e.id === Number(id)) : {};
24 | return { ...defaults, ...currEvent }
25 | },
26 | [events, id]
27 | );
28 |
29 | const [event, setEvent] = useState(initialEventState);
30 | const [formErrors, setFormErrors] = useState({});
31 | const dateInput = useRef(null);
32 |
33 | const updateEvent = (key, value) => {
34 | setEvent((prevEvent) => ({ ...prevEvent, [key]: value }));
35 | };
36 |
37 | useEffect(() => {
38 | const p = new Pikaday({
39 | field: dateInput.current,
40 | toString: date => formatDate(date),
41 | onSelect: (date) => {
42 | const formattedDate = formatDate(date);
43 | dateInput.current.value = formattedDate;
44 | updateEvent('event_date', formattedDate);
45 | },
46 | });
47 |
48 | // Return a cleanup function.
49 | // React will call this prior to unmounting.
50 | return () => p.destroy();
51 | }, []);
52 |
53 | const handleInputChange = (e) => {
54 | const { target } = e;
55 | const { name } = target;
56 | const value = target.type === 'checkbox' ? target.checked : target.value;
57 |
58 | updateEvent(name, value);
59 | };
60 |
61 | useEffect(() => {
62 | setEvent(initialEventState);
63 | }, [events, initialEventState]);
64 |
65 | const renderErrors = () => {
66 | if (isEmptyObject(formErrors)) return null;
67 |
68 | return (
69 |
70 |
The following errors prohibited the event from being saved:
71 |
72 | {Object.values(formErrors).map((formError) => (
73 | - {formError}
74 | ))}
75 |
76 |
77 | );
78 | };
79 |
80 | const handleSubmit = (e) => {
81 | e.preventDefault();
82 | const errors = validateEvent(event);
83 |
84 | if (!isEmptyObject(errors)) {
85 | setFormErrors(errors);
86 | } else {
87 | onSave(event);
88 | }
89 | };
90 |
91 | const cancelURL = event.id ? `/events/${event.id}` : '/events';
92 | const title = event.id ? `${event.event_date} - ${event.event_type}` : 'New Event';
93 |
94 | if (id && !event.id) return ;
95 |
96 | return (
97 |
98 |
{title}
99 | {renderErrors()}
100 |
101 |
182 |
183 | );
184 | };
185 |
186 | export default EventForm;
187 |
188 | EventForm.propTypes = {
189 | events: PropTypes.arrayOf(
190 | PropTypes.shape({
191 | id: PropTypes.number.isRequired,
192 | event_type: PropTypes.string.isRequired,
193 | event_date: PropTypes.string.isRequired,
194 | title: PropTypes.string.isRequired,
195 | speaker: PropTypes.string.isRequired,
196 | host: PropTypes.string.isRequired,
197 | published: PropTypes.bool.isRequired,
198 | })
199 | ),
200 | onSave: PropTypes.func.isRequired,
201 | };
202 |
203 | EventForm.defaultProps = {
204 | events: [],
205 | };
206 |
--------------------------------------------------------------------------------
/app/javascript/components/EventList.js:
--------------------------------------------------------------------------------
1 | import React, { useState, useRef } from 'react';
2 | import PropTypes from 'prop-types';
3 | import { Link, NavLink } from 'react-router-dom';
4 |
5 | const EventList = ({ events }) => {
6 | const [searchTerm, setSearchTerm] = useState('');
7 | const searchInput = useRef(null);
8 |
9 | const updateSearchTerm = () => {
10 | setSearchTerm(searchInput.current.value);
11 | };
12 |
13 | const matchSearchTerm = (obj) => {
14 | // eslint-disable-next-line camelcase
15 | const { id, published, created_at, updated_at, ...rest } = obj;
16 | return Object.values(rest).some(
17 | (value) => value.toLowerCase().indexOf(searchTerm.toLowerCase()) > -1
18 | );
19 | };
20 |
21 | const renderEvents = (eventArray) =>
22 | eventArray
23 | .filter((el) => matchSearchTerm(el))
24 | .sort((a, b) => new Date(b.event_date) - new Date(a.event_date))
25 | .map((event) => (
26 |
27 |
28 | {event.event_date}
29 | {' - '}
30 | {event.event_type}
31 |
32 |
33 | ));
34 |
35 | return (
36 |
52 | );
53 | };
54 |
55 | EventList.propTypes = {
56 | events: PropTypes.arrayOf(
57 | PropTypes.shape({
58 | id: PropTypes.number.isRequired,
59 | event_type: PropTypes.string.isRequired,
60 | event_date: PropTypes.string.isRequired,
61 | title: PropTypes.string.isRequired,
62 | speaker: PropTypes.string.isRequired,
63 | host: PropTypes.string.isRequired,
64 | published: PropTypes.bool.isRequired,
65 | })
66 | ).isRequired,
67 | };
68 |
69 | export default EventList;
70 |
--------------------------------------------------------------------------------
/app/javascript/components/EventNotFound.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | const EventNotFound = () => Event not found!
;
4 |
5 | export default EventNotFound;
6 |
--------------------------------------------------------------------------------
/app/javascript/components/Header.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Link } from 'react-router-dom';
3 |
4 | const Header = () => (
5 |
6 |
7 | Event Manager
8 |
9 |
10 | );
11 |
12 | export default Header;
13 |
--------------------------------------------------------------------------------
/app/javascript/controllers/application.js:
--------------------------------------------------------------------------------
1 | /* global window */
2 |
3 | import { Application } from '@hotwired/stimulus';
4 |
5 | const application = Application.start();
6 |
7 | // Configure Stimulus development experience
8 | application.debug = false;
9 | window.Stimulus = application;
10 |
11 | export { application };
12 |
--------------------------------------------------------------------------------
/app/javascript/controllers/hello_controller.js:
--------------------------------------------------------------------------------
1 | import { Controller } from '@hotwired/stimulus';
2 |
3 | export default class extends Controller {
4 | connect() {
5 | this.element.textContent = 'Hello World!';
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/app/javascript/controllers/index.js:
--------------------------------------------------------------------------------
1 | // This file is auto-generated by ./bin/rails stimulus:manifest:update
2 | // Run that command whenever you add a new controller or create them with
3 | // ./bin/rails generate stimulus controllerName
4 |
5 | import { application } from './application';
6 |
7 | import HelloController from './hello_controller';
8 |
9 | application.register('hello', HelloController);
10 |
--------------------------------------------------------------------------------
/app/javascript/helpers/helpers.js:
--------------------------------------------------------------------------------
1 | import { error } from './notifications';
2 |
3 | export const isEmptyObject = (obj) => Object.keys(obj).length === 0;
4 |
5 | const isValidDate = (dateObj) => !Number.isNaN(Date.parse(dateObj));
6 |
7 | export const validateEvent = (event) => {
8 | const errors = {};
9 |
10 | if (event.event_type === '') {
11 | errors.event_type = 'You must enter an event type';
12 | }
13 |
14 | if (event.event_date === '') {
15 | errors.event_date = 'You must enter a valid date';
16 | }
17 |
18 | if (!isValidDate(event.event_date)) {
19 | errors.event_date = 'You must enter a valid date';
20 | }
21 |
22 | if (event.title === '') {
23 | errors.title = 'You must enter a title';
24 | }
25 |
26 | if (event.speaker === '') {
27 | errors.speaker = 'You must enter at least one speaker';
28 | }
29 |
30 | if (event.host === '') {
31 | errors.host = 'You must enter at least one host';
32 | }
33 |
34 | return errors;
35 | };
36 |
37 | export const formatDate = (d) => {
38 | const YYYY = d.getFullYear();
39 | const MM = `0${d.getMonth() + 1}`.slice(-2);
40 | const DD = `0${d.getDate()}`.slice(-2);
41 |
42 | return `${YYYY}-${MM}-${DD}`;
43 | };
44 |
45 | export const handleAjaxError = (err) => {
46 | error('Something went wrong');
47 | console.error(err);
48 | };
49 |
--------------------------------------------------------------------------------
/app/javascript/helpers/notifications.js:
--------------------------------------------------------------------------------
1 | import { toast, Flip } from 'react-toastify';
2 | import 'react-toastify/dist/ReactToastify.css';
3 |
4 | const defaults = {
5 | position: 'top-right',
6 | autoClose: 5000,
7 | hideProgressBar: true,
8 | closeOnClick: true,
9 | pauseOnHover: true,
10 | draggable: true,
11 | progress: undefined,
12 | transition: Flip,
13 | };
14 |
15 | export const success = (message, options = {}) => {
16 | toast.success(message, Object.assign(defaults, options));
17 | };
18 |
19 | export const info = (message, options = {}) => {
20 | toast.info(message, Object.assign(defaults, options));
21 | };
22 |
23 | export const warn = (message, options = {}) => {
24 | toast.warn(message, Object.assign(defaults, options));
25 | };
26 |
27 | export const error = (message, options = {}) => {
28 | toast.error(message, Object.assign(defaults, options));
29 | };
30 |
--------------------------------------------------------------------------------
/app/jobs/application_job.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class ApplicationJob < ActiveJob::Base
4 | # Automatically retry jobs that encountered a deadlock
5 | # retry_on ActiveRecord::Deadlocked
6 |
7 | # Most jobs are safe to ignore if the underlying records are no longer available
8 | # discard_on ActiveJob::DeserializationError
9 | end
10 |
--------------------------------------------------------------------------------
/app/mailers/application_mailer.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class ApplicationMailer < ActionMailer::Base
4 | default from: 'from@example.com'
5 | layout 'mailer'
6 | end
7 |
--------------------------------------------------------------------------------
/app/models/application_record.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class ApplicationRecord < ActiveRecord::Base
4 | primary_abstract_class
5 | end
6 |
--------------------------------------------------------------------------------
/app/models/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/app/models/concerns/.keep
--------------------------------------------------------------------------------
/app/models/event.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class Event < ApplicationRecord
4 | end
5 |
--------------------------------------------------------------------------------
/app/views/layouts/application.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ReactRailsCrudApp
5 |
6 | <%= csrf_meta_tags %>
7 | <%= csp_meta_tag %>
8 |
9 |
10 |
11 |
15 |
16 | <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
17 | <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
18 |
19 |
20 |
21 | <%= yield %>
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/views/layouts/mailer.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
9 |
10 |
11 | <%= yield %>
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/views/layouts/mailer.text.erb:
--------------------------------------------------------------------------------
1 | <%= yield %>
2 |
--------------------------------------------------------------------------------
/app/views/site/index.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/bin/bundle:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # frozen_string_literal: true
3 |
4 | #
5 | # This file was generated by Bundler.
6 | #
7 | # The application 'bundle' is installed as part of a gem, and
8 | # this file is here to facilitate running it.
9 | #
10 |
11 | require "rubygems"
12 |
13 | m = Module.new do
14 | module_function
15 |
16 | def invoked_as_script?
17 | File.expand_path($0) == File.expand_path(__FILE__)
18 | end
19 |
20 | def env_var_version
21 | ENV["BUNDLER_VERSION"]
22 | end
23 |
24 | def cli_arg_version
25 | return unless invoked_as_script? # don't want to hijack other binstubs
26 | return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
27 | bundler_version = nil
28 | update_index = nil
29 | ARGV.each_with_index do |a, i|
30 | if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
31 | bundler_version = a
32 | end
33 | next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
34 | bundler_version = $1
35 | update_index = i
36 | end
37 | bundler_version
38 | end
39 |
40 | def gemfile
41 | gemfile = ENV["BUNDLE_GEMFILE"]
42 | return gemfile if gemfile && !gemfile.empty?
43 |
44 | File.expand_path("../../Gemfile", __FILE__)
45 | end
46 |
47 | def lockfile
48 | lockfile =
49 | case File.basename(gemfile)
50 | when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
51 | else "#{gemfile}.lock"
52 | end
53 | File.expand_path(lockfile)
54 | end
55 |
56 | def lockfile_version
57 | return unless File.file?(lockfile)
58 | lockfile_contents = File.read(lockfile)
59 | return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
60 | Regexp.last_match(1)
61 | end
62 |
63 | def bundler_requirement
64 | @bundler_requirement ||=
65 | env_var_version || cli_arg_version ||
66 | bundler_requirement_for(lockfile_version)
67 | end
68 |
69 | def bundler_requirement_for(version)
70 | return "#{Gem::Requirement.default}.a" unless version
71 |
72 | bundler_gem_version = Gem::Version.new(version)
73 |
74 | requirement = bundler_gem_version.approximate_recommendation
75 |
76 | return requirement unless Gem.rubygems_version < Gem::Version.new("2.7.0")
77 |
78 | requirement += ".a" if bundler_gem_version.prerelease?
79 |
80 | requirement
81 | end
82 |
83 | def load_bundler!
84 | ENV["BUNDLE_GEMFILE"] ||= gemfile
85 |
86 | activate_bundler
87 | end
88 |
89 | def activate_bundler
90 | gem_error = activation_error_handling do
91 | gem "bundler", bundler_requirement
92 | end
93 | return if gem_error.nil?
94 | require_error = activation_error_handling do
95 | require "bundler/version"
96 | end
97 | return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
98 | warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
99 | exit 42
100 | end
101 |
102 | def activation_error_handling
103 | yield
104 | nil
105 | rescue StandardError, LoadError => e
106 | e
107 | end
108 | end
109 |
110 | m.load_bundler!
111 |
112 | if m.invoked_as_script?
113 | load Gem.bin_path("bundler", "bundle")
114 | end
115 |
--------------------------------------------------------------------------------
/bin/dev:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | if ! command -v foreman &> /dev/null
4 | then
5 | echo "Installing foreman..."
6 | gem install foreman
7 | fi
8 |
9 | foreman start -f Procfile.dev "$@"
10 |
--------------------------------------------------------------------------------
/bin/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | APP_PATH = File.expand_path("../config/application", __dir__)
3 | require_relative "../config/boot"
4 | require "rails/commands"
5 |
--------------------------------------------------------------------------------
/bin/rake:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require_relative "../config/boot"
3 | require "rake"
4 | Rake.application.run
5 |
--------------------------------------------------------------------------------
/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require "fileutils"
3 |
4 | # path to your application root.
5 | APP_ROOT = File.expand_path("..", __dir__)
6 |
7 | def system!(*args)
8 | system(*args) || abort("\n== Command #{args} failed ==")
9 | end
10 |
11 | FileUtils.chdir APP_ROOT do
12 | # This script is a way to set up or update your development environment automatically.
13 | # This script is idempotent, so that you can run it at any time and get an expectable outcome.
14 | # Add necessary setup steps to this file.
15 |
16 | puts "== Installing dependencies =="
17 | system! "gem install bundler --conservative"
18 | system("bundle check") || system!("bundle install")
19 |
20 | # puts "\n== Copying sample files =="
21 | # unless File.exist?("config/database.yml")
22 | # FileUtils.cp "config/database.yml.sample", "config/database.yml"
23 | # end
24 |
25 | puts "\n== Preparing database =="
26 | system! "bin/rails db:prepare"
27 |
28 | puts "\n== Removing old logs and tempfiles =="
29 | system! "bin/rails log:clear tmp:clear"
30 |
31 | puts "\n== Restarting application server =="
32 | system! "bin/rails restart"
33 | end
34 |
--------------------------------------------------------------------------------
/config.ru:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # This file is used by Rack-based servers to start the application.
4 |
5 | require_relative 'config/environment'
6 |
7 | run Rails.application
8 | Rails.application.load_server
9 |
--------------------------------------------------------------------------------
/config/application.rb:
--------------------------------------------------------------------------------
1 | require_relative "boot"
2 |
3 | require "rails/all"
4 |
5 | # Require the gems listed in Gemfile, including any gems
6 | # you've limited to :test, :development, or :production.
7 | Bundler.require(*Rails.groups)
8 |
9 | module ReactRailsCrudApp
10 | class Application < Rails::Application
11 | # Initialize configuration defaults for originally generated Rails version.
12 | config.load_defaults 7.0
13 |
14 | # Configuration for the application, engines, and railties goes here.
15 | #
16 | # These settings can be overridden in specific environments using the files
17 | # in config/environments, which are processed later.
18 | #
19 | # config.time_zone = "Central Time (US & Canada)"
20 | # config.eager_load_paths << Rails.root.join("extras")
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/config/boot.rb:
--------------------------------------------------------------------------------
1 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
2 |
3 | require "bundler/setup" # Set up gems listed in the Gemfile.
4 | require "bootsnap/setup" # Speed up boot time by caching expensive operations.
5 |
--------------------------------------------------------------------------------
/config/cable.yml:
--------------------------------------------------------------------------------
1 | development:
2 | adapter: async
3 |
4 | test:
5 | adapter: test
6 |
7 | production:
8 | adapter: redis
9 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
10 | channel_prefix: react_rails_crud_app_production
11 |
--------------------------------------------------------------------------------
/config/credentials.yml.enc:
--------------------------------------------------------------------------------
1 | 4SL8qr66MgBmc/Whet0xIvnQ2ABlR+T+NylsT3jwOyxikDCMwfzgW+R4NPZjkuhdGGwv9TQEdo2+kTplcx2BaIR06BlDxOEBBx30mjqIg8miCPaz88nggqY1DsrhXAzh0jXXMgkcfYN6EhCofOaxVOizdKgiZLOvVz2O3rytHSA8HtfJeE2LesgDgpn/DxH4NHjy97G/k5334H8dgEGBaC7QBNOu3RiEu8SX2ajFqIZ4JW2NxfCkupQ8p+G2jg8G5K3Bi7nRCA0pU+fmSQBa3EG3ZpDw0L41K+79sYnrCy7/m72hvUa3mkZg411+j/wHFW6t55QZKjFY07XPbz14k8eAUcAZrEIOTm6tqpXtUtQXcbOIN5Kn8RVu3RIMFvknFzxVbDmKqx/KjSnkwoCfmKzySQqIPzgIJbQO--8gibITgfFDjUa8HE--HSh7QGPAvcw45MCACkHZtg==
--------------------------------------------------------------------------------
/config/database.yml:
--------------------------------------------------------------------------------
1 | # SQLite. Versions 3.8.0 and up are supported.
2 | # gem install sqlite3
3 | #
4 | # Ensure the SQLite 3 gem is defined in your Gemfile
5 | # gem "sqlite3"
6 | #
7 | default: &default
8 | adapter: sqlite3
9 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
10 | timeout: 5000
11 |
12 | development:
13 | <<: *default
14 | database: db/development.sqlite3
15 |
16 | # Warning: The database defined as "test" will be erased and
17 | # re-generated from your development database when you run "rake".
18 | # Do not set this db to the same as development or production.
19 | test:
20 | <<: *default
21 | database: db/test.sqlite3
22 |
23 | production:
24 | <<: *default
25 | database: db/production.sqlite3
26 |
--------------------------------------------------------------------------------
/config/environment.rb:
--------------------------------------------------------------------------------
1 | # Load the Rails application.
2 | require_relative "application"
3 |
4 | # Initialize the Rails application.
5 | Rails.application.initialize!
6 |
--------------------------------------------------------------------------------
/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | require "active_support/core_ext/integer/time"
2 |
3 | Rails.application.configure do
4 | # Settings specified here will take precedence over those in config/application.rb.
5 |
6 | # In the development environment your application's code is reloaded any time
7 | # it changes. This slows down response time but is perfect for development
8 | # since you don't have to restart the web server when you make code changes.
9 | config.cache_classes = false
10 |
11 | # Do not eager load code on boot.
12 | config.eager_load = false
13 |
14 | # Show full error reports.
15 | config.consider_all_requests_local = true
16 |
17 | # Enable server timing
18 | config.server_timing = true
19 |
20 | # Enable/disable caching. By default caching is disabled.
21 | # Run rails dev:cache to toggle caching.
22 | if Rails.root.join("tmp/caching-dev.txt").exist?
23 | config.action_controller.perform_caching = true
24 | config.action_controller.enable_fragment_cache_logging = true
25 |
26 | config.cache_store = :memory_store
27 | config.public_file_server.headers = {
28 | "Cache-Control" => "public, max-age=#{2.days.to_i}"
29 | }
30 | else
31 | config.action_controller.perform_caching = false
32 |
33 | config.cache_store = :null_store
34 | end
35 |
36 | # Store uploaded files on the local file system (see config/storage.yml for options).
37 | config.active_storage.service = :local
38 |
39 | # Don't care if the mailer can't send.
40 | config.action_mailer.raise_delivery_errors = false
41 |
42 | config.action_mailer.perform_caching = false
43 |
44 | # Print deprecation notices to the Rails logger.
45 | config.active_support.deprecation = :log
46 |
47 | # Raise exceptions for disallowed deprecations.
48 | config.active_support.disallowed_deprecation = :raise
49 |
50 | # Tell Active Support which deprecation messages to disallow.
51 | config.active_support.disallowed_deprecation_warnings = []
52 |
53 | # Raise an error on page load if there are pending migrations.
54 | config.active_record.migration_error = :page_load
55 |
56 | # Highlight code that triggered database queries in logs.
57 | config.active_record.verbose_query_logs = true
58 |
59 | # Suppress logger output for asset requests.
60 | config.assets.quiet = true
61 |
62 | # Raises error for missing translations.
63 | # config.i18n.raise_on_missing_translations = true
64 |
65 | # Annotate rendered view with file names.
66 | # config.action_view.annotate_rendered_view_with_filenames = true
67 |
68 | # Uncomment if you wish to allow Action Cable access from any origin.
69 | # config.action_cable.disable_request_forgery_protection = true
70 | end
71 |
--------------------------------------------------------------------------------
/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | require "active_support/core_ext/integer/time"
2 |
3 | Rails.application.configure do
4 | # Settings specified here will take precedence over those in config/application.rb.
5 |
6 | # Code is not reloaded between requests.
7 | config.cache_classes = true
8 |
9 | # Eager load code on boot. This eager loads most of Rails and
10 | # your application in memory, allowing both threaded web servers
11 | # and those relying on copy on write to perform better.
12 | # Rake tasks automatically ignore this option for performance.
13 | config.eager_load = true
14 |
15 | # Full error reports are disabled and caching is turned on.
16 | config.consider_all_requests_local = false
17 | config.action_controller.perform_caching = true
18 |
19 | # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
20 | # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
21 | # config.require_master_key = true
22 |
23 | # Disable serving static files from the `/public` folder by default since
24 | # Apache or NGINX already handles this.
25 | config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?
26 |
27 | # Compress CSS using a preprocessor.
28 | # config.assets.css_compressor = :sass
29 |
30 | # Do not fallback to assets pipeline if a precompiled asset is missed.
31 | config.assets.compile = false
32 |
33 | # Enable serving of images, stylesheets, and JavaScripts from an asset server.
34 | # config.asset_host = "http://assets.example.com"
35 |
36 | # Specifies the header that your server uses for sending files.
37 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache
38 | # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX
39 |
40 | # Store uploaded files on the local file system (see config/storage.yml for options).
41 | config.active_storage.service = :local
42 |
43 | # Mount Action Cable outside main process or domain.
44 | # config.action_cable.mount_path = nil
45 | # config.action_cable.url = "wss://example.com/cable"
46 | # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ]
47 |
48 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
49 | # config.force_ssl = true
50 |
51 | # Include generic and useful information about system operation, but avoid logging too much
52 | # information to avoid inadvertent exposure of personally identifiable information (PII).
53 | config.log_level = :info
54 |
55 | # Prepend all log lines with the following tags.
56 | config.log_tags = [ :request_id ]
57 |
58 | # Use a different cache store in production.
59 | # config.cache_store = :mem_cache_store
60 |
61 | # Use a real queuing backend for Active Job (and separate queues per environment).
62 | # config.active_job.queue_adapter = :resque
63 | # config.active_job.queue_name_prefix = "react_rails_crud_app_production"
64 |
65 | config.action_mailer.perform_caching = false
66 |
67 | # Ignore bad email addresses and do not raise email delivery errors.
68 | # Set this to true and configure the email server for immediate delivery to raise delivery errors.
69 | # config.action_mailer.raise_delivery_errors = false
70 |
71 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
72 | # the I18n.default_locale when a translation cannot be found).
73 | config.i18n.fallbacks = true
74 |
75 | # Don't log any deprecations.
76 | config.active_support.report_deprecations = false
77 |
78 | # Use default logging formatter so that PID and timestamp are not suppressed.
79 | config.log_formatter = ::Logger::Formatter.new
80 |
81 | # Use a different logger for distributed setups.
82 | # require "syslog/logger"
83 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name")
84 |
85 | if ENV["RAILS_LOG_TO_STDOUT"].present?
86 | logger = ActiveSupport::Logger.new(STDOUT)
87 | logger.formatter = config.log_formatter
88 | config.logger = ActiveSupport::TaggedLogging.new(logger)
89 | end
90 |
91 | # Do not dump schema after migrations.
92 | config.active_record.dump_schema_after_migration = false
93 | end
94 |
--------------------------------------------------------------------------------
/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | require "active_support/core_ext/integer/time"
2 |
3 | # The test environment is used exclusively to run your application's
4 | # test suite. You never need to work with it otherwise. Remember that
5 | # your test database is "scratch space" for the test suite and is wiped
6 | # and recreated between test runs. Don't rely on the data there!
7 |
8 | Rails.application.configure do
9 | # Settings specified here will take precedence over those in config/application.rb.
10 |
11 | # Turn false under Spring and add config.action_view.cache_template_loading = true.
12 | config.cache_classes = true
13 |
14 | # Eager loading loads your whole application. When running a single test locally,
15 | # this probably isn't necessary. It's a good idea to do in a continuous integration
16 | # system, or in some way before deploying your code.
17 | config.eager_load = ENV["CI"].present?
18 |
19 | # Configure public file server for tests with Cache-Control for performance.
20 | config.public_file_server.enabled = true
21 | config.public_file_server.headers = {
22 | "Cache-Control" => "public, max-age=#{1.hour.to_i}"
23 | }
24 |
25 | # Show full error reports and disable caching.
26 | config.consider_all_requests_local = true
27 | config.action_controller.perform_caching = false
28 | config.cache_store = :null_store
29 |
30 | # Raise exceptions instead of rendering exception templates.
31 | config.action_dispatch.show_exceptions = false
32 |
33 | # Disable request forgery protection in test environment.
34 | config.action_controller.allow_forgery_protection = false
35 |
36 | # Store uploaded files on the local file system in a temporary directory.
37 | config.active_storage.service = :test
38 |
39 | config.action_mailer.perform_caching = false
40 |
41 | # Tell Action Mailer not to deliver emails to the real world.
42 | # The :test delivery method accumulates sent emails in the
43 | # ActionMailer::Base.deliveries array.
44 | config.action_mailer.delivery_method = :test
45 |
46 | # Print deprecation notices to the stderr.
47 | config.active_support.deprecation = :stderr
48 |
49 | # Raise exceptions for disallowed deprecations.
50 | config.active_support.disallowed_deprecation = :raise
51 |
52 | # Tell Active Support which deprecation messages to disallow.
53 | config.active_support.disallowed_deprecation_warnings = []
54 |
55 | # Raises error for missing translations.
56 | # config.i18n.raise_on_missing_translations = true
57 |
58 | # Annotate rendered view with file names.
59 | # config.action_view.annotate_rendered_view_with_filenames = true
60 | end
61 |
--------------------------------------------------------------------------------
/config/initializers/assets.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Version of your assets, change this if you want to expire all your assets.
4 | Rails.application.config.assets.version = "1.0"
5 |
6 | # Add additional assets to the asset load path.
7 | # Rails.application.config.assets.paths << Emoji.images_path
8 |
9 | # Precompile additional assets.
10 | # application.js, application.css, and all non-JS/CSS in the app/assets
11 | # folder are already added.
12 | # Rails.application.config.assets.precompile += %w( admin.js admin.css )
13 |
--------------------------------------------------------------------------------
/config/initializers/content_security_policy.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Define an application-wide content security policy
4 | # For further information see the following documentation
5 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
6 |
7 | # Rails.application.configure do
8 | # config.content_security_policy do |policy|
9 | # policy.default_src :self, :https
10 | # policy.font_src :self, :https, :data
11 | # policy.img_src :self, :https, :data
12 | # policy.object_src :none
13 | # policy.script_src :self, :https
14 | # policy.style_src :self, :https
15 | # # Specify URI for violation reports
16 | # # policy.report_uri "/csp-violation-report-endpoint"
17 | # end
18 | #
19 | # # Generate session nonces for permitted importmap and inline scripts
20 | # config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s }
21 | # config.content_security_policy_nonce_directives = %w(script-src)
22 | #
23 | # # Report CSP violations to a specified URI. See:
24 | # # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
25 | # # config.content_security_policy_report_only = true
26 | # end
27 |
--------------------------------------------------------------------------------
/config/initializers/filter_parameter_logging.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Configure parameters to be filtered from the log file. Use this to limit dissemination of
4 | # sensitive information. See the ActiveSupport::ParameterFilter documentation for supported
5 | # notations and behaviors.
6 | Rails.application.config.filter_parameters += [
7 | :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn
8 | ]
9 |
--------------------------------------------------------------------------------
/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new inflection rules using the following format. Inflections
4 | # are locale specific, and you may define rules for as many different
5 | # locales as you wish. All of these examples are active by default:
6 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
7 | # inflect.plural /^(ox)$/i, "\\1en"
8 | # inflect.singular /^(ox)en/i, "\\1"
9 | # inflect.irregular "person", "people"
10 | # inflect.uncountable %w( fish sheep )
11 | # end
12 |
13 | # These inflection rules are supported but not enabled by default:
14 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
15 | # inflect.acronym "RESTful"
16 | # end
17 |
--------------------------------------------------------------------------------
/config/initializers/permissions_policy.rb:
--------------------------------------------------------------------------------
1 | # Define an application-wide HTTP permissions policy. For further
2 | # information see https://developers.google.com/web/updates/2018/06/feature-policy
3 | #
4 | # Rails.application.config.permissions_policy do |f|
5 | # f.camera :none
6 | # f.gyroscope :none
7 | # f.microphone :none
8 | # f.usb :none
9 | # f.fullscreen :self
10 | # f.payment :self, "https://secure.example.com"
11 | # end
12 |
--------------------------------------------------------------------------------
/config/locales/en.yml:
--------------------------------------------------------------------------------
1 | # Files in the config/locales directory are used for internationalization
2 | # and are automatically loaded by Rails. If you want to use locales other
3 | # than English, add the necessary files in this directory.
4 | #
5 | # To use the locales, use `I18n.t`:
6 | #
7 | # I18n.t "hello"
8 | #
9 | # In views, this is aliased to just `t`:
10 | #
11 | # <%= t("hello") %>
12 | #
13 | # To use a different locale, set it with `I18n.locale`:
14 | #
15 | # I18n.locale = :es
16 | #
17 | # This would use the information in config/locales/es.yml.
18 | #
19 | # The following keys must be escaped otherwise they will not be retrieved by
20 | # the default I18n backend:
21 | #
22 | # true, false, on, off, yes, no
23 | #
24 | # Instead, surround them with single quotes.
25 | #
26 | # en:
27 | # "true": "foo"
28 | #
29 | # To learn more, please read the Rails Internationalization guide
30 | # available at https://guides.rubyonrails.org/i18n.html.
31 |
32 | en:
33 | hello: "Hello world"
34 |
--------------------------------------------------------------------------------
/config/puma.rb:
--------------------------------------------------------------------------------
1 | # Puma can serve each request in a thread from an internal thread pool.
2 | # The `threads` method setting takes two numbers: a minimum and maximum.
3 | # Any libraries that use thread pools should be configured to match
4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum
5 | # and maximum; this matches the default thread size of Active Record.
6 | #
7 | max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
8 | min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
9 | threads min_threads_count, max_threads_count
10 |
11 | # Specifies the `worker_timeout` threshold that Puma will use to wait before
12 | # terminating a worker in development environments.
13 | #
14 | worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development"
15 |
16 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
17 | #
18 | port ENV.fetch("PORT") { 3000 }
19 |
20 | # Specifies the `environment` that Puma will run in.
21 | #
22 | environment ENV.fetch("RAILS_ENV") { "development" }
23 |
24 | # Specifies the `pidfile` that Puma will use.
25 | pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
26 |
27 | # Specifies the number of `workers` to boot in clustered mode.
28 | # Workers are forked web server processes. If using threads and workers together
29 | # the concurrency of the application would be max `threads` * `workers`.
30 | # Workers do not work on JRuby or Windows (both of which do not support
31 | # processes).
32 | #
33 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
34 |
35 | # Use the `preload_app!` method when specifying a `workers` number.
36 | # This directive tells Puma to first boot the application and load code
37 | # before forking the application. This takes advantage of Copy On Write
38 | # process behavior so workers use less memory.
39 | #
40 | # preload_app!
41 |
42 | # Allow puma to be restarted by `bin/rails restart` command.
43 | plugin :tmp_restart
44 |
--------------------------------------------------------------------------------
/config/routes.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | Rails.application.routes.draw do
4 | root to: redirect('/events')
5 |
6 | get 'events', to: 'site#index'
7 | get 'events/new', to: 'site#index'
8 | get 'events/:id', to: 'site#index'
9 | get 'events/:id/edit', to: 'site#index'
10 |
11 | namespace :api do
12 | resources :events, only: %i[index show create destroy update]
13 | end
14 | end
15 |
--------------------------------------------------------------------------------
/config/storage.yml:
--------------------------------------------------------------------------------
1 | test:
2 | service: Disk
3 | root: <%= Rails.root.join("tmp/storage") %>
4 |
5 | local:
6 | service: Disk
7 | root: <%= Rails.root.join("storage") %>
8 |
9 | # Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
10 | # amazon:
11 | # service: S3
12 | # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
13 | # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
14 | # region: us-east-1
15 | # bucket: your_own_bucket-<%= Rails.env %>
16 |
17 | # Remember not to checkin your GCS keyfile to a repository
18 | # google:
19 | # service: GCS
20 | # project: your_project
21 | # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
22 | # bucket: your_own_bucket-<%= Rails.env %>
23 |
24 | # Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
25 | # microsoft:
26 | # service: AzureStorage
27 | # storage_account_name: your_account_name
28 | # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
29 | # container: your_container_name-<%= Rails.env %>
30 |
31 | # mirror:
32 | # service: Mirror
33 | # primary: local
34 | # mirrors: [ amazon, google, microsoft ]
35 |
--------------------------------------------------------------------------------
/db/migrate/20220313134908_create_events.rb:
--------------------------------------------------------------------------------
1 | class CreateEvents < ActiveRecord::Migration[7.0]
2 | def change
3 | create_table :events do |t|
4 | t.string :event_type
5 | t.date :event_date
6 | t.text :title
7 | t.string :speaker
8 | t.string :host
9 | t.boolean :published
10 |
11 | t.timestamps
12 | end
13 | end
14 | end
15 |
--------------------------------------------------------------------------------
/db/schema.rb:
--------------------------------------------------------------------------------
1 | # This file is auto-generated from the current state of the database. Instead
2 | # of editing this file, please use the migrations feature of Active Record to
3 | # incrementally modify your database, and then regenerate this schema definition.
4 | #
5 | # This file is the source Rails uses to define your schema when running `bin/rails
6 | # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7 | # be faster and is potentially less error prone than running all of your
8 | # migrations from scratch. Old migrations may fail to apply correctly if those
9 | # migrations use external dependencies or application code.
10 | #
11 | # It's strongly recommended that you check this file into your version control system.
12 |
13 | ActiveRecord::Schema[7.0].define(version: 2022_03_13_134908) do
14 | create_table "events", force: :cascade do |t|
15 | t.string "event_type"
16 | t.date "event_date"
17 | t.text "title"
18 | t.string "speaker"
19 | t.string "host"
20 | t.boolean "published"
21 | t.datetime "created_at", null: false
22 | t.datetime "updated_at", null: false
23 | end
24 |
25 | end
26 |
--------------------------------------------------------------------------------
/db/seeds.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | json = ActiveSupport::JSON.decode(File.read('db/seeds/events.json'))
4 | json.each do |record|
5 | Event.create!(record)
6 | end
7 |
--------------------------------------------------------------------------------
/db/seeds/events.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "event_type": "Symposium",
4 | "event_date": "2022-07-14",
5 | "title": "Ada Lovelace — The Making of a Computer Scientist",
6 | "speaker": "Monica S. Lam, Yoky Matsuoka, Dorit Aharonov",
7 | "host": "Ursula Martin",
8 | "published": false
9 | },
10 | {
11 | "event_type": "Colloquium",
12 | "event_date": "2022-04-12",
13 | "title": "Scholasticism in Medieval and Early Modern History",
14 | "speaker": "Robin Fleming",
15 | "host": "Henry Louis Gates Jr.",
16 | "published": true
17 | },
18 | {
19 | "event_type": "Symposium",
20 | "event_date": "2022-03-30",
21 | "title": "Charles II and the English Restoration",
22 | "speaker": "Kate Williams, Patrick Morrah, Charles Spencer",
23 | "host": "Lucy Worsley",
24 | "published": true
25 | },
26 | {
27 | "event_type": "Symposium",
28 | "event_date": "2022-03-01",
29 | "title": "Remembering the Titanic, One of the Greatest Ever Maritime Tragedies",
30 | "speaker": "William Hazelgrove, Lauren Tarshis, Andrew Wilson",
31 | "host": "Dan Snow",
32 | "published": true
33 | },
34 | {
35 | "event_type": "Symposium",
36 | "event_date": "2022-02-07",
37 | "title": "Symbolism in Portraits of Queen Elizabeth I",
38 | "speaker": "David Starkey, Susan Doran, Alison Weir",
39 | "host": "Suzannah Lipscomb",
40 | "published": true
41 | },
42 | {
43 | "event_type": "Colloquium",
44 | "event_date": "2021-12-19",
45 | "title": "A Brief History Of China's Dynasties",
46 | "speaker": "Iris Chang",
47 | "host": "Pamela Kyle Crossley",
48 | "published": true
49 | }
50 | ]
51 |
--------------------------------------------------------------------------------
/lib/assets/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/lib/assets/.keep
--------------------------------------------------------------------------------
/lib/tasks/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/lib/tasks/.keep
--------------------------------------------------------------------------------
/log/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/log/.keep
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Event-Manager",
3 | "private": "true",
4 | "dependencies": {
5 | "@hotwired/stimulus": "^3.0.1",
6 | "@hotwired/turbo-rails": "^7.1.1",
7 | "esbuild": "^0.14.25",
8 | "pikaday": "^1.8.2",
9 | "prop-types": "^15.8.1",
10 | "react": "^18.0.0",
11 | "react-dom": "^18.0.0",
12 | "react-router-dom": "^6.2.2",
13 | "react-toastify": "^8.2.0"
14 | },
15 | "scripts": {
16 | "build": "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds --loader:.js=jsx",
17 | "watch": "esbuild app/javascript/*.* --watch --bundle --outdir=app/assets/builds --loader:.js=jsx"
18 | },
19 | "devDependencies": {
20 | "eslint": "^8.11.0",
21 | "eslint-config-airbnb": "^19.0.4",
22 | "eslint-config-prettier": "^8.5.0",
23 | "eslint-plugin-import": "^2.25.3",
24 | "eslint-plugin-jsx-a11y": "^6.5.1",
25 | "eslint-plugin-react": "^7.28.0",
26 | "eslint-plugin-react-hooks": "^4.3.0"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The page you were looking for doesn't exist (404)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
The page you were looking for doesn't exist.
62 |
You may have mistyped the address or the page may have moved.
63 |
64 |
If you are the application owner check the logs for more information.
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/public/422.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The change you wanted was rejected (422)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
The change you wanted was rejected.
62 |
Maybe you tried to change something you didn't have access to.
63 |
64 |
If you are the application owner check the logs for more information.
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/public/500.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | We're sorry, but something went wrong (500)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
We're sorry, but something went wrong.
62 |
63 |
If you are the application owner check the logs for more information.
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/public/apple-touch-icon-precomposed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/public/apple-touch-icon-precomposed.png
--------------------------------------------------------------------------------
/public/apple-touch-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/public/apple-touch-icon.png
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/public/favicon.ico
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2 |
--------------------------------------------------------------------------------
/storage/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/storage/.keep
--------------------------------------------------------------------------------
/test/application_system_test_case.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'test_helper'
4 |
5 | class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
6 | driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
7 | end
8 |
--------------------------------------------------------------------------------
/test/channels/application_cable/connection_test.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'test_helper'
4 |
5 | class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase
6 | # test "connects with cookies" do
7 | # cookies.signed[:user_id] = 42
8 | #
9 | # connect
10 | #
11 | # assert_equal connection.user_id, "42"
12 | # end
13 | end
14 |
--------------------------------------------------------------------------------
/test/controllers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/test/controllers/.keep
--------------------------------------------------------------------------------
/test/controllers/site_controller_test.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'test_helper'
4 |
5 | class SiteControllerTest < ActionDispatch::IntegrationTest
6 | test 'should get index' do
7 | get site_index_url
8 | assert_response :success
9 | end
10 | end
11 |
--------------------------------------------------------------------------------
/test/fixtures/events.yml:
--------------------------------------------------------------------------------
1 | # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2 |
3 | one:
4 | event_type: MyString
5 | event_date: 2022-03-13
6 | title: MyText
7 | speaker: MyString
8 | host: MyString
9 | published: false
10 |
11 | two:
12 | event_type: MyString
13 | event_date: 2022-03-13
14 | title: MyText
15 | speaker: MyString
16 | host: MyString
17 | published: false
18 |
--------------------------------------------------------------------------------
/test/fixtures/files/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/test/fixtures/files/.keep
--------------------------------------------------------------------------------
/test/helpers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/test/helpers/.keep
--------------------------------------------------------------------------------
/test/integration/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/test/integration/.keep
--------------------------------------------------------------------------------
/test/mailers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/test/mailers/.keep
--------------------------------------------------------------------------------
/test/models/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/test/models/.keep
--------------------------------------------------------------------------------
/test/models/event_test.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'test_helper'
4 |
5 | class EventTest < ActiveSupport::TestCase
6 | # test "the truth" do
7 | # assert true
8 | # end
9 | end
10 |
--------------------------------------------------------------------------------
/test/system/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/test/system/.keep
--------------------------------------------------------------------------------
/test/test_helper.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | ENV['RAILS_ENV'] ||= 'test'
4 | require_relative '../config/environment'
5 | require 'rails/test_help'
6 |
7 | class ActiveSupport::TestCase
8 | # Run tests in parallel with specified workers
9 | parallelize(workers: :number_of_processors)
10 |
11 | # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
12 | fixtures :all
13 |
14 | # Add more helper methods to be used by all tests here...
15 | end
16 |
--------------------------------------------------------------------------------
/tmp/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/tmp/.keep
--------------------------------------------------------------------------------
/tmp/pids/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/tmp/pids/.keep
--------------------------------------------------------------------------------
/tmp/storage/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/tmp/storage/.keep
--------------------------------------------------------------------------------
/vendor/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jameshibbard/react-rails-crud-app/e6b0f9596a6e590f9489272154972e1395ffffc9/vendor/.keep
--------------------------------------------------------------------------------