Custom Scaffold Templates
Create a
templates
folder in thelib
directory.Create
erb
folders intemplates
directory.Create a
scaffold
folder insideerb
directory.Create
index.html.erb
file inscaffold
directory.
Inside
index.html.erb
file in scaffold directory.
A number of things to note:
This assumes you created a new rails app using my Kickoff Tailwind template. The classes you see pertain to Tailwind CSS as well as some custom components that come by default when you create a new rails app using the template. I talk more about recent changes to the template here.
The
<%%
signs are new and essentially act as a templating preformatter when a scaffold gets run within the context oferb
files.Inside these templates, we have access to local variables and methods like
singular_table_name
orsingular_route_name
of which are dynamic. These will get replaced with whatever resource you’re generating. In our case, it would bepost
.
Last updated