Skip to content

Commit

Permalink
run scaffold, migrate, webpack - server is broken for some reason
Browse files Browse the repository at this point in the history
  • Loading branch information
compwron committed Mar 29, 2020
1 parent eea2fc6 commit 6a0a9f7
Show file tree
Hide file tree
Showing 37 changed files with 8,293 additions and 5 deletions.
1 change: 1 addition & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
defaults
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Things you may want to cover:
1. rails db:create # requires running local postgres
1. rails generate scaffold Case case_number:string teen_program_eligible:boolean
1. rake db:migrate
1. Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/
1. brew install yarm OR https://yarnpkg.com/lang/en/docs/install/
1. rails webpacker:install
1. rails server

Expand Down
3 changes: 3 additions & 0 deletions app/assets/stylesheets/cases.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Cases controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
65 changes: 65 additions & 0 deletions app/assets/stylesheets/scaffolds.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
body {
background-color: #fff;
color: #333;
margin: 33px; }

body, p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px; }

pre {
background-color: #eee;
padding: 10px;
font-size: 11px; }

a {
color: #000; }

a:visited {
color: #666; }

a:hover {
color: #fff;
background-color: #000; }

th {
padding-bottom: 5px; }

td {
padding: 0 5px 7px; }

div.field,
div.actions {
margin-bottom: 10px; }

#notice {
color: green; }

.field_with_errors {
padding: 2px;
background-color: red;
display: table; }

#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px 7px 0;
margin-bottom: 20px;
background-color: #f0f0f0; }

#error_explanation h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px -7px 0;
background-color: #c00;
color: #fff; }

#error_explanation ul li {
font-size: 12px;
list-style: square; }

label {
display: block; }
74 changes: 74 additions & 0 deletions app/controllers/cases_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class CasesController < ApplicationController
before_action :set_case, only: [:show, :edit, :update, :destroy]

# GET /cases
# GET /cases.json
def index
@cases = Case.all
end

# GET /cases/1
# GET /cases/1.json
def show
end

# GET /cases/new
def new
@case = Case.new
end

# GET /cases/1/edit
def edit
end

# POST /cases
# POST /cases.json
def create
@case = Case.new(case_params)

respond_to do |format|
if @case.save
format.html { redirect_to @case, notice: 'Case was successfully created.' }
format.json { render :show, status: :created, location: @case }
else
format.html { render :new }
format.json { render json: @case.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /cases/1
# PATCH/PUT /cases/1.json
def update
respond_to do |format|
if @case.update(case_params)
format.html { redirect_to @case, notice: 'Case was successfully updated.' }
format.json { render :show, status: :ok, location: @case }
else
format.html { render :edit }
format.json { render json: @case.errors, status: :unprocessable_entity }
end
end
end

# DELETE /cases/1
# DELETE /cases/1.json
def destroy
@case.destroy
respond_to do |format|
format.html { redirect_to cases_url, notice: 'Case was successfully destroyed.' }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_case
@case = Case.find(params[:id])
end

# Only allow a list of trusted parameters through.
def case_params
params.require(:case).permit(:case_number, :teen_program_eligible)
end
end
2 changes: 2 additions & 0 deletions app/helpers/cases_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module CasesHelper
end
2 changes: 2 additions & 0 deletions app/models/case.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Case < ApplicationRecord
end
2 changes: 2 additions & 0 deletions app/views/cases/_case.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! case, :id, :case_number, :teen_program_eligible, :created_at, :updated_at
json.url case_url(case, format: :json)
27 changes: 27 additions & 0 deletions app/views/cases/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<%= form_with(model: case, local: true) do |form| %>
<% if case.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(case.errors.count, "error") %> prohibited this case from being saved:</h2>

<ul>
<% case.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= form.label :case_number %>
<%= form.text_field :case_number %>
</div>

<div class="field">
<%= form.label :teen_program_eligible %>
<%= form.check_box :teen_program_eligible %>
</div>

<div class="actions">
<%= form.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/cases/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing Case</h1>

<%= render 'form', case: @case %>

<%= link_to 'Show', @case %> |
<%= link_to 'Back', cases_path %>
29 changes: 29 additions & 0 deletions app/views/cases/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<p id="notice"><%= notice %></p>

<h1>Cases</h1>

<table>
<thead>
<tr>
<th>Case number</th>
<th>Teen program eligible</th>
<th colspan="3"></th>
</tr>
</thead>

<tbody>
<% @cases.each do |case| %>
<tr>
<td><%= case.case_number %></td>
<td><%= case.teen_program_eligible %></td>
<td><%= link_to 'Show', case %></td>
<td><%= link_to 'Edit', edit_case_path(case) %></td>
<td><%= link_to 'Destroy', case, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>

<br>

<%= link_to 'New Case', new_case_path %>
1 change: 1 addition & 0 deletions app/views/cases/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @cases, partial: "cases/case", as: :case
5 changes: 5 additions & 0 deletions app/views/cases/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New Case</h1>

<%= render 'form', case: @case %>

<%= link_to 'Back', cases_path %>
14 changes: 14 additions & 0 deletions app/views/cases/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<p id="notice"><%= notice %></p>

<p>
<strong>Case number:</strong>
<%= @case.case_number %>
</p>

<p>
<strong>Teen program eligible:</strong>
<%= @case.teen_program_eligible %>
</p>

<%= link_to 'Edit', edit_case_path(@case) %> |
<%= link_to 'Back', cases_path %>
1 change: 1 addition & 0 deletions app/views/cases/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "cases/case", case: @case
72 changes: 72 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
module.exports = function(api) {
var validEnv = ['development', 'test', 'production']
var currentEnv = api.env()
var isDevelopmentEnv = api.env('development')
var isProductionEnv = api.env('production')
var isTestEnv = api.env('test')

if (!validEnv.includes(currentEnv)) {
throw new Error(
'Please specify a valid `NODE_ENV` or ' +
'`BABEL_ENV` environment variables. Valid values are "development", ' +
'"test", and "production". Instead, received: ' +
JSON.stringify(currentEnv) +
'.'
)
}

return {
presets: [
isTestEnv && [
'@babel/preset-env',
{
targets: {
node: 'current'
}
}
],
(isProductionEnv || isDevelopmentEnv) && [
'@babel/preset-env',
{
forceAllTransforms: true,
useBuiltIns: 'entry',
corejs: 3,
modules: false,
exclude: ['transform-typeof-symbol']
}
]
].filter(Boolean),
plugins: [
'babel-plugin-macros',
'@babel/plugin-syntax-dynamic-import',
isTestEnv && 'babel-plugin-dynamic-import-node',
'@babel/plugin-transform-destructuring',
[
'@babel/plugin-proposal-class-properties',
{
loose: true
}
],
[
'@babel/plugin-proposal-object-rest-spread',
{
useBuiltIns: true
}
],
[
'@babel/plugin-transform-runtime',
{
helpers: false,
regenerator: true,
corejs: false
}
],
[
'@babel/plugin-transform-regenerator',
{
async: false
}
]
].filter(Boolean)
}
}
18 changes: 18 additions & 0 deletions bin/webpack
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env ruby

ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
ENV["NODE_ENV"] ||= "development"

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require "bundler/setup"

require "webpacker"
require "webpacker/webpack_runner"

APP_ROOT = File.expand_path("..", __dir__)
Dir.chdir(APP_ROOT) do
Webpacker::WebpackRunner.run(ARGV)
end
18 changes: 18 additions & 0 deletions bin/webpack-dev-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env ruby

ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
ENV["NODE_ENV"] ||= "development"

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require "bundler/setup"

require "webpacker"
require "webpacker/dev_server_runner"

APP_ROOT = File.expand_path("..", __dir__)
Dir.chdir(APP_ROOT) do
Webpacker::DevServerRunner.run(ARGV)
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Rails.application.routes.draw do
resources :cases
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end
5 changes: 5 additions & 0 deletions config/webpack/development.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'development'

const environment = require('./environment')

module.exports = environment.toWebpackConfig()
3 changes: 3 additions & 0 deletions config/webpack/environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { environment } = require('@rails/webpacker')

module.exports = environment
5 changes: 5 additions & 0 deletions config/webpack/production.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'production'

const environment = require('./environment')

module.exports = environment.toWebpackConfig()
5 changes: 5 additions & 0 deletions config/webpack/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'development'

const environment = require('./environment')

module.exports = environment.toWebpackConfig()
Loading

0 comments on commit 6a0a9f7

Please sign in to comment.