Skip to content

Commit 86c8600

Browse files
committed
Install Inertia
1 parent e39870a commit 86c8600

File tree

24 files changed

+966
-7
lines changed

24 files changed

+966
-7
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,5 @@ gem 'tailwindcss-rails', '~> 2.0'
128128
gem 'opentelemetry-exporter-otlp', '~> 0.26.1'
129129
gem 'opentelemetry-instrumentation-all', '~> 0.50.1'
130130
gem 'opentelemetry-sdk', '~> 1.3'
131+
132+
gem "inertia_rails", "~> 3.17"

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ GEM
300300
image_processing (1.13.0)
301301
mini_magick (>= 4.9.5, < 5)
302302
ruby-vips (>= 2.0.17, < 3)
303+
inertia_rails (3.17.0)
304+
railties (>= 6)
303305
io-console (0.8.0)
304306
irb (1.14.3)
305307
rdoc (>= 4.0.0)
@@ -835,6 +837,7 @@ DEPENDENCIES
835837
html2text
836838
htmlbeautifier
837839
image_processing
840+
inertia_rails (~> 3.17)
838841
jbuilder (~> 2.7)
839842
json_csv
840843
jsonb_accessor (= 1.3.2)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
class InertiaController < ApplicationController
4+
# Share data with all Inertia responses
5+
# see https://inertia-rails.dev/guide/shared-data
6+
# inertia_share user: -> { Current.user&.as_json(only: [:id, :name, :email]) }
7+
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
class InertiaExampleController < InertiaController
4+
def index
5+
render inertia: {
6+
rails_version: Rails.version,
7+
ruby_version: RUBY_DESCRIPTION,
8+
rack_version: Rack.release,
9+
inertia_rails_version: InertiaRails::VERSION,
10+
}
11+
end
12+
end

app/javascript/assets/inertia.svg

Lines changed: 1 addition & 0 deletions
Loading

app/javascript/assets/rails.svg

Lines changed: 9 additions & 0 deletions
Loading

app/javascript/assets/react.svg

Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { createInertiaApp, type ResolvedComponent } from '@inertiajs/react'
2+
import { StrictMode } from 'react'
3+
import { createRoot } from 'react-dom/client'
4+
5+
void createInertiaApp({
6+
// Set default page title
7+
// see https://inertia-rails.dev/guide/title-and-meta
8+
//
9+
// title: title => title ? `${title} - App` : 'App',
10+
11+
// Disable progress bar
12+
//
13+
// see https://inertia-rails.dev/guide/progress-indicators
14+
// progress: false,
15+
16+
resolve: (name) => {
17+
const pages = import.meta.glob<{default: ResolvedComponent}>('../pages/**/*.tsx', {
18+
eager: true,
19+
})
20+
const page = pages[`../pages/${name}.tsx`]
21+
if (!page) {
22+
console.error(`Missing Inertia page component: '${name}.tsx'`)
23+
}
24+
25+
// To use a default layout, import the Layout component
26+
// and use the following line.
27+
// see https://inertia-rails.dev/guide/pages#default-layouts
28+
//
29+
// page.default.layout ||= (page: ReactNode) => (<Layout>{page}</Layout>)
30+
31+
return page
32+
},
33+
34+
setup({ el, App, props }) {
35+
createRoot(el).render(
36+
<StrictMode>
37+
<App {...props} />
38+
</StrictMode>
39+
)
40+
},
41+
42+
defaults: {
43+
form: {
44+
forceIndicesArrayFormatInFormData: false,
45+
},
46+
future: {
47+
useScriptElementForInitialPage: true,
48+
useDataInertiaHeadAttribute: true,
49+
useDialogForErrorModal: true,
50+
preserveEqualProps: true,
51+
},
52+
},
53+
}).catch((error) => {
54+
// This ensures this entrypoint is only loaded on Inertia pages
55+
// by checking for the presence of the root element (#app by default).
56+
// Feel free to remove this `catch` if you don't need it.
57+
if (document.getElementById("app")) {
58+
throw error
59+
} else {
60+
console.error(
61+
"Missing root element.\n\n" +
62+
"If you see this error, it probably means you loaded Inertia.js on non-Inertia pages.\n" +
63+
'Consider moving <%= vite_typescript_tag "inertia.tsx" %> to the Inertia-specific layout instead.',
64+
)
65+
}
66+
})
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
.root {
2+
box-sizing: border-box;
3+
margin: 0;
4+
padding: 0;
5+
align-items: center;
6+
background-color: #F0E7E9;
7+
background-image: url(data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjEwMjQiIHZpZXdCb3g9IjAgMCAxNDQwIDEwMjQiIHdpZHRoPSIxNDQwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Im0xNDQwIDUxMC4wMDA2NDh2LTUxMC4wMDA2NDhoLTE0NDB2Mzg0LjAwMDY0OGM0MTcuMzExOTM5IDEzMS4xNDIxNzkgODkxIDE3MS41MTMgMTQ0MCAxMjZ6IiBmaWxsPSIjZmZmIi8+PC9zdmc+);
8+
background-position: center center;
9+
background-repeat: no-repeat;
10+
background-size: cover;
11+
color: #261B23;
12+
display: flex;
13+
flex-direction: column;
14+
font-family: Sans-Serif;
15+
font-size: calc(0.9em + 0.5vw);
16+
font-style: normal;
17+
font-weight: 400;
18+
justify-content: center;
19+
line-height: 1.25;
20+
min-height: 100vh;
21+
text-align: center;
22+
}
23+
24+
@media (prefers-color-scheme: dark) {
25+
.root {
26+
background-color: #1a1a1a;
27+
background-image: url(data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjEwMjQiIHZpZXdCb3g9IjAgMCAxNDQwIDEwMjQiIHdpZHRoPSIxNDQwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Im0xNDQwIDUxMC4wMDA2NDh2LTUxMC4wMDA2NDhoLTE0NDB2Mzg0LjAwMDY0OGM0MTcuMzExOTM5IDEzMS4xNDIxNzkgODkxIDE3MS41MTMgMTQ0MCAxMjZ6IiBmaWxsPSIjMzMzIi8+PC9zdmc+);
28+
color: #e0e0e0;
29+
}
30+
}
31+
32+
.logo {
33+
display: inline-block;
34+
height: 9.8vw;
35+
min-height: 130px;
36+
padding: 1.5em;
37+
will-change: filter;
38+
transition: filter 300ms;
39+
filter: drop-shadow(0 20px 13px rgb(0 0 0 / 0.03)) drop-shadow(0 8px 5px rgb(0 0 0 / 0.08));
40+
}
41+
.logo.inertia:hover {
42+
filter: drop-shadow(0 0 2em #646cffaa);
43+
}
44+
.logo.react:hover {
45+
filter: drop-shadow(0 0 2em #61dafbaa);
46+
}
47+
.logo.rails:hover {
48+
filter: drop-shadow(0 0 2em rgb(211 0 1 / 0.6));
49+
}
50+
51+
@keyframes logo-spin {
52+
from {
53+
transform: rotate(0deg);
54+
}
55+
to {
56+
transform: rotate(360deg);
57+
}
58+
}
59+
60+
@media (prefers-reduced-motion: no-preference) {
61+
.logo.react {
62+
animation: logo-spin infinite 20s linear;
63+
}
64+
}
65+
66+
@media (prefers-color-scheme: dark) {
67+
.logo {
68+
filter: drop-shadow(0 20px 13px rgb(255 255 255 / 0.03)) drop-shadow(0 8px 5px rgb(255 255 255 / 0.08));
69+
}
70+
}
71+
72+
.card {
73+
padding: 2em;
74+
font-size: 0.7em;
75+
color: #948e90;
76+
}
77+
78+
.footer {
79+
bottom: 0;
80+
left: 0;
81+
margin: 0 2rem 2rem 2rem;
82+
position: absolute;
83+
right: 0;
84+
}
85+
86+
.footer ul {
87+
list-style: none;
88+
}
89+
90+
.footer ul li {
91+
display: inline;
92+
}
93+
94+
.footer ul ul li:after {
95+
content: " | ";
96+
font-weight: 300;
97+
color: #948e90;
98+
}
99+
100+
.footer ul ul li:last-child:after {
101+
content: "";
102+
}

0 commit comments

Comments
 (0)