Skip to Content
Modern Front-End Development for Rails
book

Modern Front-End Development for Rails

by Noel Rappin
June 2021
Intermediate to advanced
398 pages
9h 35m
English
Pragmatic Bookshelf
Content preview from Modern Front-End Development for Rails

Going Generic

In our case, what do generic Stimulus controllers look like?

What we have now is one controller that responds to a click by showing or hiding a target element and by changing the text of a target.

Let’s think a bit more abstractly, and what we have here are two separate actions that respond to a click: one that adds and removes a CSS class and one that changes the text of a button. we’re going to split those into two separate controllers to show how Stimulus allows for composition of small, generic pieces of action.

Now, there’s an obvious downside here, which is that the code and the HTML are going to get more verbose. Let’s look at the code and then talk about the upsides.

Both the generic Stimulus controllers are mostly subsets ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Modern Front-End Development for Rails, 2nd Edition

Modern Front-End Development for Rails, 2nd Edition

Noel Rappin
Agile Web Development with Rails 6

Agile Web Development with Rails 6

Sam Ruby, David B. Copeland, Dave Thomas

Publisher Resources

ISBN: 9781680508758Errata Page