Web Application Design: Ruby on Rails scaffolded interfaces v6 vs v7
I learned a funny thing while building a test application for my next posts, which is that Rails changed their scaffolding templates in 2.7.
I don’t expect it to change my overall plans very much, but here’s a little tangent on the changes.
Here’s the activity diagram from the last post representing the scaffolding in Rails 6.
And here’s what it has been changed to:
We can see that most of the links involving the resource have been
moved to the show
view, and index
just has links to show
(for
each resource listed in the index) and new
. This makes sense. It’s
still a good base to start from. I plan on exploring the
implementation of “rich” views in which the features for updating and
creating are incorporated into index
and show
, but not having any
intimations of that in the base provided from the scaffolding isn’t
going to complicate the exploration of that any.
In Rails 6 (and before) index
represented all it’s resources in a
table, which was a different representation from show
. In Rails 7
index
and show
render the representation in the same model-partial
which resembles the Rails 6 show
representation: attribute fields in
paragraphs.
The case for this is that, with the additional example, it better
illustrates partials, and is more coherent with the partials used for
the JSON views, and sure, it definitely does and is. However,
personally, I’ve never liked the show
representation, because what
even is that. The form
partial used by new
and edit
is for
representing resources as a form. If we had different views with
tables we were going to represent the model on maybe we’d have
partials for representing these models as rows. A big app might have
lots of representations for a single model and many places where they
are rendered to users. There might even be different JSON
representations in an API. If nothing else, I don’t think the partial
should be named after the model as if it were some canonical
representation, but maybe name it “basic” or “static” or
something. Anyway, I’m planning on getting to that aspect, but maybe
sooner than I was first thinking.
Another thing I was thinking of covering, which might also come up sooner than I expected, are techniques of making your own generators and scaffolding. If you have a big Rails app, and you have some standardized or even merely conventional ways was representing new resources, writing your own scaffolding for them is a big time saver.
Okay, that’s a survey of the scaffolding changes in Rails 7 which I hadn’t even looked at before my last post.