Skip to content

Replace Webpacker with importmapped Hotwire as default JavaScript setup#42999

Merged
dhh merged 64 commits intomainfrom
replace-webpack-with-importmapped-hotwire-as-default-js
Aug 26, 2021
Merged

Replace Webpacker with importmapped Hotwire as default JavaScript setup#42999
dhh merged 64 commits intomainfrom
replace-webpack-with-importmapped-hotwire-as-default-js

Conversation

@dhh
Copy link
Member

@dhh dhh commented Aug 11, 2021

A default Rails skeleton should not have to require the full JavaScript toolchain with Webpack by default. Let's start with an importmapped Hotwire, then make it easy to go from there to Webpack, if needed later. Though we'll retain --webpack as an option for everyone who knows they'll need the full JS chain (like if doing React).

The new options are as follows:

  1. rails new produces a skeleton configured with importmap-rails, turbo-rails, and stimulus-rails. No Webpack, no Yarn, no package.json, no node. All the integration setup is done through adding the gems, then running importmap:install, turbo:install, stimulus:install tasks.
  2. rails new —skip-hotwire a skeleton like above but with just importmap-rails configured.
  3. rails new —skip-javascript no JavaScript setup of any kind is configured.
  4. rails new —webpack is essentially what we had on Rails 6.2, with the exception that the default Turbolinks configuration is replaced with Hotwire (both Turbo and Stimulus). This of course includes setting up package.json, Yarn, etc.
  5. rails new —webpack —skip-hotwire is the same as above, minus the default configuration of Hotwire.

In line with the upcoming Webpacker 6, we’ve dropped the —webpack=framework preconfiguration. —webpack is now a boolean flag.

Alpha preview of what this feels like: https://www.youtube.com/watch?v=PtxZvFnL2i0&t=334s

@rails-bot rails-bot bot added the railties label Aug 11, 2021
@dhh
Copy link
Member Author

dhh commented Aug 14, 2021

If anyone would like to help with this effort, I’d appreciate some assistance fixing all the remaining tests ✌️

@zokaibr
Copy link

zokaibr commented Aug 14, 2021

It may not be the best First Issue to start collaborating on Rails, but I want to give a try.
Even if I can't reach anything, at least I read some Rails code 🙂

@dhh dhh merged commit af7428c into main Aug 26, 2021
@dhh dhh deleted the replace-webpack-with-importmapped-hotwire-as-default-js branch August 26, 2021 08:39
@dhh dhh changed the title Replace webpack with importmapped Hotwire as default js Replace Webpacker with importmapped Hotwire as default JavaScript setup Aug 26, 2021
seanpdoyle added a commit to thoughtbot/hotwire-example-template that referenced this pull request Sep 3, 2021
The upcoming release of [Rails 7][] will be notable for numerous
reasons. One of the more remarkable announcements involves the
deprecation of Rails UJS and the switch to [Hotwire][] as Rails'
[default JavaScript framework][].

Let's learn more about how Hotwire fits into Rails by building an
Article drafting experience that provides end-users with a preview of
their final version as they type!

We'll start with an out-of-the-box Rails installation that utilizes
Turbo Drive, Turbo Streams, and Stimulus to then progressively enhance
concepts and tools that are built directly into browsers. Plus, it'll
degrade gracefully when JavaScript is unavailable!

The code samples contained within omit the majority of the application's
setup. While reading, know that the bulk of the application's code was
generated by a `rails new` command

The rest of the source code from this article can be found [on
GitHub][].

[Hotwire]: https://hotwired.dev
[Rails 7]: https://edgeguides.rubyonrails.org/7_0_release_notes.html
[default JavaScript framework]: rails/rails#42999
[on GitHub]: https://github.com/seanpdoyle/hotwire-example-template/commits/hotwire-example-live-preview

Drafting Articles
===

We'll start by using Rails `model` generator to create some `Article`
[scaffolding][] code to serve as a starting point for our extensions and
customizations:

```sh
bin/rails generate scaffold Article content:text
bin/rails db:migrate
```

We won't be making any changes to the vast majority of the generated code, but
there are two view partials that will be changed the most throughout the rest of
the article. To have context for those changes, it's worth becoming familiar
with them before we get started: `app/views/articles/_form.html.erb` and
`app/views/articles/_article.html.erb`.

The `articles/form` partial renders a single `<textarea>` field for our
`Article` model's `content`, along with an `<input type="submit">`
element:

```erb
<%= form_with(model: article) do |form| %>
  <% if article.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(article.errors.count, "error") %> prohibited this article from being saved:</h2>

      <ul>
        <% article.errors.each do |error| %>
          <li><%= error.full_message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= form.label :content %>
    <%= form.text_area :content %>
  </div>

  <div class="actions">
    <%= form.submit %>
  </div>
<% end %>
```

Similarly, the `articles/article` partial renders the value of the
`content` as plain text:

```erb
<div id="<%= dom_id article %>" class="scaffold_record">
  <p>
    <strong>Content:</strong>
    <%= article.content %>
  </p>

  <p>
    <%= link_to "Show this article", article %>
  </p>
</div>
```

The rest of the generated code serves as the foundation for creating,
reading, updating, and destroying `Article` instances. While it's
crucial, they're implementation details that we can ignore for the sake
of this example.

[scaffolding]: https://edgeguides.rubyonrails.org/getting_started.html#mvc-and-you-generating-a-model
seanpdoyle added a commit to thoughtbot/hotwire-example-template that referenced this pull request Sep 3, 2021
The upcoming [Rails 7][] release will be notable for numerous reasons.
One of the more remarkable being the deprecation and removal of Rails
UJS, and the introduction of [Hotwire][] as Rails' [default JavaScript
framework][].

Let's learn more about how Hotwire fits into Rails by building an
Article drafting experience that provides end-users with a preview of
their final version as they type!

We'll start with an out-of-the-box Rails installation that utilizes
Turbo Drive, Turbo Streams, and Stimulus to then progressively enhance
concepts and tools that are built directly into browsers. Plus, it'll
degrade gracefully when JavaScript is unavailable!

The code samples contained within omit the majority of the application's
setup. While reading, know that the bulk of the application's code was
generated by a `rails new` command

The rest of the source code from this article can be found [on
GitHub][].

[Hotwire]: https://hotwired.dev
[Rails 7]: https://edgeguides.rubyonrails.org/7_0_release_notes.html
[default JavaScript framework]: rails/rails#42999
[on GitHub]: https://github.com/seanpdoyle/hotwire-example-template/commits/hotwire-example-live-preview

Drafting Articles
===

We'll start by using Rails `model` generator to create some `Article`
[scaffolding][] code to serve as a starting point for our extensions and
customizations:

```sh
bin/rails generate scaffold Article content:text
bin/rails db:migrate
```

We won't be making any changes to the vast majority of the generated code, but
there are two view partials that will be changed the most throughout the rest of
the article. To have context for those changes, it's worth becoming familiar
with them before we get started: `app/views/articles/_form.html.erb` and
`app/views/articles/_article.html.erb`.

The `articles/form` partial renders a single `<textarea>` field for our
`Article` model's `content`, along with an `<input type="submit">`
element:

```erb
<%= form_with(model: article) do |form| %>
  <% if article.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(article.errors.count, "error") %> prohibited this article from being saved:</h2>

      <ul>
        <% article.errors.each do |error| %>
          <li><%= error.full_message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= form.label :content %>
    <%= form.text_area :content %>
  </div>

  <div class="actions">
    <%= form.submit %>
  </div>
<% end %>
```

Similarly, the `articles/article` partial renders the value of the
`content` as plain text:

```erb
<div id="<%= dom_id article %>" class="scaffold_record">
  <p>
    <strong>Content:</strong>
    <%= article.content %>
  </p>

  <p>
    <%= link_to "Show this article", article %>
  </p>
</div>
```

The rest of the generated code serves as the foundation for creating,
reading, updating, and destroying `Article` instances. While it's
crucial, they're implementation details that we can ignore for the sake
of this example.

[scaffolding]: https://edgeguides.rubyonrails.org/getting_started.html#mvc-and-you-generating-a-model
seanpdoyle added a commit to thoughtbot/hotwire-example-template that referenced this pull request Sep 10, 2021
The upcoming [Rails 7][] release will be notable for numerous reasons.
One of the more remarkable being the deprecation and removal of Rails
UJS, and the introduction of [Hotwire][] as Rails' [default JavaScript
framework][].

Let's learn more about how Hotwire fits into Rails by building an
Article drafting experience that provides end-users with a preview of
their final version as they type!

We'll start with an out-of-the-box Rails installation that utilizes
Turbo Drive, Turbo Streams, and Stimulus to then progressively enhance
concepts and tools that are built directly into browsers. Plus, it'll
degrade gracefully when JavaScript is unavailable!

The code samples contained within omit the majority of the application's
setup. While reading, know that the bulk of the application's code was
generated by a `rails new` command

The rest of the source code from this article can be found [on
GitHub][].

[Hotwire]: https://hotwired.dev
[Rails 7]: https://edgeguides.rubyonrails.org/7_0_release_notes.html
[default JavaScript framework]: rails/rails#42999
[on GitHub]: https://github.com/thoughtbot/hotwire-example-template/commits/hotwire-example-live-preview

Drafting Articles
===

We'll start by using Rails `model` generator to create some `Article`
[scaffolding][] code to serve as a starting point for our extensions and
customizations:

```sh
bin/rails generate scaffold Article content:text
bin/rails db:migrate
```

We won't be making any changes to the vast majority of the generated code, but
there are two view partials that will be changed the most throughout the rest of
the article. To have context for those changes, it's worth becoming familiar
with them before we get started: `app/views/articles/_form.html.erb` and
`app/views/articles/_article.html.erb`.

The `articles/form` partial renders a single `<textarea>` field for our
`Article` model's `content`, along with an `<input type="submit">`
element:

```erb
<%= form_with(model: article) do |form| %>
  <% if article.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(article.errors.count, "error") %> prohibited this article from being saved:</h2>

      <ul>
        <% article.errors.each do |error| %>
          <li><%= error.full_message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= form.label :content %>
    <%= form.text_area :content %>
  </div>

  <div class="actions">
    <%= form.submit %>
  </div>
<% end %>
```

Similarly, the `articles/article` partial renders the value of the
`content` as plain text:

```erb
<div id="<%= dom_id article %>" class="scaffold_record">
  <p>
    <strong>Content:</strong>
    <%= article.content %>
  </p>

  <p>
    <%= link_to "Show this article", article %>
  </p>
</div>
```

The rest of the generated code serves as the foundation for creating,
reading, updating, and destroying `Article` instances. While it's
crucial, they're implementation details that we can ignore for the sake
of this example.

[scaffolding]: https://edgeguides.rubyonrails.org/getting_started.html#mvc-and-you-generating-a-model
seanpdoyle added a commit to thoughtbot/hotwire-example-template that referenced this pull request Sep 15, 2021
The upcoming [Rails 7][] release will be notable for numerous reasons.
One of the more remarkable being the deprecation and removal of Rails
UJS, and the introduction of [Hotwire][] as Rails' [default JavaScript
framework][].

Let's learn more about how Hotwire fits into Rails by building an
Article drafting experience that provides end-users with a preview of
their final version as they type!

We'll start with an out-of-the-box Rails installation that utilizes
Turbo Drive, Turbo Streams, and Stimulus to then progressively enhance
concepts and tools that are built directly into browsers. Plus, it'll
degrade gracefully when JavaScript is unavailable!

The code samples contained within omit the majority of the application's
setup. While reading, know that the bulk of the application's code was
generated by a `rails new` command

The rest of the source code from this article can be found [on
GitHub][].

[Hotwire]: https://hotwired.dev
[Rails 7]: https://edgeguides.rubyonrails.org/7_0_release_notes.html
[default JavaScript framework]: rails/rails#42999
[on GitHub]: https://github.com/thoughtbot/hotwire-example-template/commits/hotwire-example-live-preview

Drafting Articles
===

We'll start by using Rails `model` generator to create some `Article`
[scaffolding][] code to serve as a starting point for our extensions and
customizations:

```sh
bin/rails generate scaffold Article content:text
bin/rails db:migrate
```

We won't be making any changes to the vast majority of the generated code, but
there are two view partials that will be changed the most throughout the rest of
the article. To have context for those changes, it's worth becoming familiar
with them before we get started: `app/views/articles/_form.html.erb` and
`app/views/articles/_article.html.erb`.

The `articles/form` partial renders a single `<textarea>` field for our
`Article` model's `content`, along with an `<input type="submit">`
element:

```erb
<%= form_with(model: article) do |form| %>
  <% if article.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(article.errors.count, "error") %> prohibited this article from being saved:</h2>

      <ul>
        <% article.errors.each do |error| %>
          <li><%= error.full_message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= form.label :content %>
    <%= form.text_area :content %>
  </div>

  <div class="actions">
    <%= form.submit %>
  </div>
<% end %>
```

Similarly, the `articles/article` partial renders the value of the
`content` as plain text:

```erb
<div id="<%= dom_id article %>" class="scaffold_record">
  <p>
    <strong>Content:</strong>
    <%= article.content %>
  </p>

  <p>
    <%= link_to "Show this article", article %>
  </p>
</div>
```

The rest of the generated code serves as the foundation for creating,
reading, updating, and destroying `Article` instances. While it's
crucial, they're implementation details that we can ignore for the sake
of this example.

[scaffolding]: https://edgeguides.rubyonrails.org/getting_started.html#mvc-and-you-generating-a-model
seanpdoyle added a commit to thoughtbot/hotwire-example-template that referenced this pull request Sep 15, 2021
The upcoming [Rails 7][] release will be notable for numerous reasons.
One of the more remarkable being the deprecation and removal of Rails
UJS, and the introduction of [Hotwire][] as Rails' [default JavaScript
framework][].

Let's learn more about how Hotwire fits into Rails by building an
Article drafting experience that provides end-users with a preview of
their final version as they type!

We'll start with an out-of-the-box Rails installation that utilizes
Turbo Drive, Turbo Streams, and Stimulus to then progressively enhance
concepts and tools that are built directly into browsers. Plus, it'll
degrade gracefully when JavaScript is unavailable!

The code samples contained within omit the majority of the application's
setup. While reading, know that the bulk of the application's code was
generated by a `rails new` command

The rest of the source code from this article can be found [on
GitHub][].

[Hotwire]: https://hotwired.dev
[Rails 7]: https://edgeguides.rubyonrails.org/7_0_release_notes.html
[default JavaScript framework]: rails/rails#42999
[on GitHub]: https://github.com/thoughtbot/hotwire-example-template/commits/hotwire-example-live-preview

Drafting Articles
===

We'll start by using Rails `model` generator to create some `Article`
[scaffolding][] code to serve as a starting point for our extensions and
customizations:

```sh
bin/rails generate scaffold Article content:text
bin/rails db:migrate
```

We won't be making any changes to the vast majority of the generated code, but
there are two view partials that will be changed the most throughout the rest of
the article. To have context for those changes, it's worth becoming familiar
with them before we get started: `app/views/articles/_form.html.erb` and
`app/views/articles/_article.html.erb`.

The `articles/form` partial renders a single `<textarea>` field for our
`Article` model's `content`, along with an `<input type="submit">`
element:

```erb
<%= form_with(model: article) do |form| %>
  <% if article.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(article.errors.count, "error") %> prohibited this article from being saved:</h2>

      <ul>
        <% article.errors.each do |error| %>
          <li><%= error.full_message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= form.label :content %>
    <%= form.text_area :content %>
  </div>

  <div class="actions">
    <%= form.submit %>
  </div>
<% end %>
```

Similarly, the `articles/article` partial renders the value of the
`content` as plain text:

```erb
<div id="<%= dom_id article %>" class="scaffold_record">
  <p>
    <strong>Content:</strong>
    <%= article.content %>
  </p>

  <p>
    <%= link_to "Show this article", article %>
  </p>
</div>
```

The rest of the generated code serves as the foundation for creating,
reading, updating, and destroying `Article` instances. While it's
crucial, they're implementation details that we can ignore for the sake
of this example.

[scaffolding]: https://edgeguides.rubyonrails.org/getting_started.html#mvc-and-you-generating-a-model
seanpdoyle added a commit to thoughtbot/hotwire-example-template that referenced this pull request Oct 12, 2021
The upcoming [Rails 7][] release will be notable for numerous reasons.
One of the more remarkable being the deprecation and removal of Rails
UJS, and the introduction of [Hotwire][] as Rails' [default JavaScript
framework][].

Let's learn more about how Hotwire fits into Rails by building an
Article drafting experience that provides end-users with a preview of
their final version as they type!

We'll start with an out-of-the-box Rails installation that utilizes
Turbo Drive, Turbo Streams, and Stimulus to then progressively enhance
concepts and tools that are built directly into browsers. Plus, it'll
degrade gracefully when JavaScript is unavailable!

The code samples contained within omit the majority of the application's
setup. While reading, know that the bulk of the application's code was
generated by a `rails new` command

The rest of the source code from this article can be found [on
GitHub][].

[Hotwire]: https://hotwired.dev
[Rails 7]: https://edgeguides.rubyonrails.org/7_0_release_notes.html
[default JavaScript framework]: rails/rails#42999
[on GitHub]: https://github.com/thoughtbot/hotwire-example-template/commits/hotwire-example-live-preview

Drafting Articles
===

We'll start by using Rails `model` generator to create some `Article`
[scaffolding][] code to serve as a starting point for our extensions and
customizations:

```sh
bin/rails generate scaffold Article content:text
bin/rails db:migrate
```

We won't be making any changes to the vast majority of the generated code, but
there are two view partials that will be changed the most throughout the rest of
the article. To have context for those changes, it's worth becoming familiar
with them before we get started: `app/views/articles/_form.html.erb` and
`app/views/articles/_article.html.erb`.

The `articles/form` partial renders a single `<textarea>` field for our
`Article` model's `content`, along with an `<input type="submit">`
element:

```erb
<%= form_with(model: article) do |form| %>
  <% if article.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(article.errors.count, "error") %> prohibited this article from being saved:</h2>

      <ul>
        <% article.errors.each do |error| %>
          <li><%= error.full_message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= form.label :content %>
    <%= form.text_area :content %>
  </div>

  <div class="actions">
    <%= form.submit %>
  </div>
<% end %>
```

Similarly, the `articles/article` partial renders the value of the
`content` as plain text:

```erb
<div id="<%= dom_id article %>" class="scaffold_record">
  <p>
    <strong>Content:</strong>
    <%= article.content %>
  </p>

  <p>
    <%= link_to "Show this article", article %>
  </p>
</div>
```

The rest of the generated code serves as the foundation for creating,
reading, updating, and destroying `Article` instances. While it's
crucial, they're implementation details that we can ignore for the sake
of this example.

[scaffolding]: https://edgeguides.rubyonrails.org/getting_started.html#mvc-and-you-generating-a-model
seanpdoyle added a commit to thoughtbot/hotwire-example-template that referenced this pull request Dec 10, 2021
The upcoming [Rails 7][] release will be notable for numerous reasons.
One of the more remarkable being the deprecation and removal of Rails
UJS, and the introduction of [Hotwire][] as Rails' [default JavaScript
framework][].

Let's learn more about how Hotwire fits into Rails by building an
Article drafting experience that provides end-users with a preview of
their final version as they type!

We'll start with an out-of-the-box Rails installation that utilizes
Turbo Drive, Turbo Streams, and Stimulus to then progressively enhance
concepts and tools that are built directly into browsers. Plus, it'll
degrade gracefully when JavaScript is unavailable!

The code samples contained within omit the majority of the application's
setup. While reading, know that the bulk of the application's code was
generated by a `rails new` command

The rest of the source code from this article can be found [on
GitHub][].

[Hotwire]: https://hotwired.dev
[Rails 7]: https://edgeguides.rubyonrails.org/7_0_release_notes.html
[default JavaScript framework]: rails/rails#42999
[on GitHub]: https://github.com/thoughtbot/hotwire-example-template/commits/hotwire-example-live-preview

Drafting Articles
===

We'll start by using Rails `model` generator to create some `Article`
[scaffolding][] code to serve as a starting point for our extensions and
customizations:

```sh
bin/rails generate scaffold Article content:text
bin/rails db:migrate
```

We won't be making any changes to the vast majority of the generated code, but
there are two view partials that will be changed the most throughout the rest of
the article. To have context for those changes, it's worth becoming familiar
with them before we get started: `app/views/articles/_form.html.erb` and
`app/views/articles/_article.html.erb`.

The `articles/form` partial renders a single `<textarea>` field for our
`Article` model's `content`, along with an `<input type="submit">`
element:

```erb
<%= form_with(model: article) do |form| %>
  <% if article.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(article.errors.count, "error") %> prohibited this article from being saved:</h2>

      <ul>
        <% article.errors.each do |error| %>
          <li><%= error.full_message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= form.label :content %>
    <%= form.text_area :content %>
  </div>

  <div class="actions">
    <%= form.submit %>
  </div>
<% end %>
```

Similarly, the `articles/article` partial renders the value of the
`content` as plain text:

```erb
<div id="<%= dom_id article %>" class="scaffold_record">
  <p>
    <strong>Content:</strong>
    <%= article.content %>
  </p>

  <p>
    <%= link_to "Show this article", article %>
  </p>
</div>
```

The rest of the generated code serves as the foundation for creating,
reading, updating, and destroying `Article` instances. While it's
crucial, they're implementation details that we can ignore for the sake
of this example.

[scaffolding]: https://edgeguides.rubyonrails.org/getting_started.html#mvc-and-you-generating-a-model
seanpdoyle added a commit to thoughtbot/hotwire-example-template that referenced this pull request Dec 10, 2021
The upcoming [Rails 7][] release will be notable for numerous reasons.
One of the more remarkable being the deprecation and removal of Rails
UJS, and the introduction of [Hotwire][] as Rails' [default JavaScript
framework][].

Let's learn more about how Hotwire fits into Rails by building an
Article drafting experience that provides end-users with a preview of
their final version as they type!

We'll start with an out-of-the-box Rails installation that utilizes
Turbo Drive, Turbo Streams, and Stimulus to then progressively enhance
concepts and tools that are built directly into browsers. Plus, it'll
degrade gracefully when JavaScript is unavailable!

The code samples contained within omit the majority of the application's
setup. While reading, know that the bulk of the application's code was
generated by a `rails new` command

The rest of the source code from this article can be found [on
GitHub][].

[Hotwire]: https://hotwired.dev
[Rails 7]: https://edgeguides.rubyonrails.org/7_0_release_notes.html
[default JavaScript framework]: rails/rails#42999
[on GitHub]: https://github.com/thoughtbot/hotwire-example-template/commits/hotwire-example-live-preview

Drafting Articles
===

We'll start by using Rails `model` generator to create some `Article`
[scaffolding][] code to serve as a starting point for our extensions and
customizations:

```sh
bin/rails generate scaffold Article content:text
bin/rails db:migrate
```

We won't be making any changes to the vast majority of the generated code, but
there are two view partials that will be changed the most throughout the rest of
the article. To have context for those changes, it's worth becoming familiar
with them before we get started: `app/views/articles/_form.html.erb` and
`app/views/articles/_article.html.erb`.

The `articles/form` partial renders a single `<textarea>` field for our
`Article` model's `content`, along with an `<input type="submit">`
element:

```erb
<%= form_with(model: article) do |form| %>
  <% if article.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(article.errors.count, "error") %> prohibited this article from being saved:</h2>

      <ul>
        <% article.errors.each do |error| %>
          <li><%= error.full_message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= form.label :content %>
    <%= form.text_area :content %>
  </div>

  <div class="actions">
    <%= form.submit %>
  </div>
<% end %>
```

Similarly, the `articles/article` partial renders the value of the
`content` as plain text:

```erb
<div id="<%= dom_id article %>" class="scaffold_record">
  <p>
    <strong>Content:</strong>
    <%= article.content %>
  </p>

  <p>
    <%= link_to "Show this article", article %>
  </p>
</div>
```

The rest of the generated code serves as the foundation for creating,
reading, updating, and destroying `Article` instances. While it's
crucial, they're implementation details that we can ignore for the sake
of this example.

[scaffolding]: https://edgeguides.rubyonrails.org/getting_started.html#mvc-and-you-generating-a-model
seanpdoyle added a commit to thoughtbot/hotwire-example-template that referenced this pull request Dec 19, 2021
The upcoming [Rails 7][] release will be notable for numerous reasons.
One of the more remarkable being the deprecation and removal of Rails
UJS, and the introduction of [Hotwire][] as Rails' [default JavaScript
framework][].

Let's learn more about how Hotwire fits into Rails by building an
Article drafting experience that provides end-users with a preview of
their final version as they type!

We'll start with an out-of-the-box Rails installation that utilizes
Turbo Drive, Turbo Streams, and Stimulus to then progressively enhance
concepts and tools that are built directly into browsers. Plus, it'll
degrade gracefully when JavaScript is unavailable!

The code samples contained within omit the majority of the application's
setup. While reading, know that the bulk of the application's code was
generated by a `rails new` command

The rest of the source code from this article can be found [on
GitHub][].

[Hotwire]: https://hotwired.dev
[Rails 7]: https://edgeguides.rubyonrails.org/7_0_release_notes.html
[default JavaScript framework]: rails/rails#42999
[on GitHub]: https://github.com/thoughtbot/hotwire-example-template/commits/hotwire-example-live-preview

Drafting Articles
===

We'll start by using Rails `model` generator to create some `Article`
[scaffolding][] code to serve as a starting point for our extensions and
customizations:

```sh
bin/rails generate scaffold Article content:text
bin/rails db:migrate
```

We won't be making any changes to the vast majority of the generated code, but
there are two view partials that will be changed the most throughout the rest of
the article. To have context for those changes, it's worth becoming familiar
with them before we get started: `app/views/articles/_form.html.erb` and
`app/views/articles/_article.html.erb`.

The `articles/form` partial renders a single `<textarea>` field for our
`Article` model's `content`, along with an `<input type="submit">`
element:

```erb
<%= form_with(model: article) do |form| %>
  <% if article.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(article.errors.count, "error") %> prohibited this article from being saved:</h2>

      <ul>
        <% article.errors.each do |error| %>
          <li><%= error.full_message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= form.label :content %>
    <%= form.text_area :content %>
  </div>

  <div class="actions">
    <%= form.submit %>
  </div>
<% end %>
```

Similarly, the `articles/article` partial renders the value of the
`content` as plain text:

```erb
<div id="<%= dom_id article %>" class="scaffold_record">
  <p>
    <strong>Content:</strong>
    <%= article.content %>
  </p>

  <p>
    <%= link_to "Show this article", article %>
  </p>
</div>
```

The rest of the generated code serves as the foundation for creating,
reading, updating, and destroying `Article` instances. While it's
crucial, they're implementation details that we can ignore for the sake
of this example.

[scaffolding]: https://edgeguides.rubyonrails.org/getting_started.html#mvc-and-you-generating-a-model
seanpdoyle added a commit to thoughtbot/hotwire-example-template that referenced this pull request Jan 25, 2022
The upcoming [Rails 7][] release will be notable for numerous reasons.
One of the more remarkable being the deprecation and removal of Rails
UJS, and the introduction of [Hotwire][] as Rails' [default JavaScript
framework][].

Let's learn more about how Hotwire fits into Rails by building an
Article drafting experience that provides end-users with a preview of
their final version as they type!

We'll start with an out-of-the-box Rails installation that utilizes
Turbo Drive, Turbo Streams, and Stimulus to then progressively enhance
concepts and tools that are built directly into browsers. Plus, it'll
degrade gracefully when JavaScript is unavailable!

The code samples contained within omit the majority of the application's
setup. While reading, know that the bulk of the application's code was
generated by a `rails new` command

The rest of the source code from this article can be found [on
GitHub][].

[Hotwire]: https://hotwired.dev
[Rails 7]: https://edgeguides.rubyonrails.org/7_0_release_notes.html
[default JavaScript framework]: rails/rails#42999
[on GitHub]: https://github.com/thoughtbot/hotwire-example-template/commits/hotwire-example-live-preview

Drafting Articles
===

We'll start by using Rails `model` generator to create some `Article`
[scaffolding][] code to serve as a starting point for our extensions and
customizations:

```sh
bin/rails generate scaffold Article content:text
bin/rails db:migrate
```

We won't be making any changes to the vast majority of the generated code, but
there are two view partials that will be changed the most throughout the rest of
the article. To have context for those changes, it's worth becoming familiar
with them before we get started: `app/views/articles/_form.html.erb` and
`app/views/articles/_article.html.erb`.

The `articles/form` partial renders a single `<textarea>` field for our
`Article` model's `content`, along with an `<input type="submit">`
element:

```erb
<%= form_with(model: article) do |form| %>
  <% if article.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(article.errors.count, "error") %> prohibited this article from being saved:</h2>

      <ul>
        <% article.errors.each do |error| %>
          <li><%= error.full_message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= form.label :content %>
    <%= form.text_area :content %>
  </div>

  <div class="actions">
    <%= form.submit %>
  </div>
<% end %>
```

Similarly, the `articles/article` partial renders the value of the
`content` as plain text:

```erb
<div id="<%= dom_id article %>" class="scaffold_record">
  <p>
    <strong>Content:</strong>
    <%= article.content %>
  </p>

  <p>
    <%= link_to "Show this article", article %>
  </p>
</div>
```

The rest of the generated code serves as the foundation for creating,
reading, updating, and destroying `Article` instances. While it's
crucial, they're implementation details that we can ignore for the sake
of this example.

[scaffolding]: https://edgeguides.rubyonrails.org/getting_started.html#mvc-and-you-generating-a-model
seanpdoyle added a commit to thoughtbot/hotwire-example-template that referenced this pull request Feb 13, 2022
The upcoming [Rails 7][] release will be notable for numerous reasons.
One of the more remarkable being the deprecation and removal of Rails
UJS, and the introduction of [Hotwire][] as Rails' [default JavaScript
framework][].

Let's learn more about how Hotwire fits into Rails by building an
Article drafting experience that provides end-users with a preview of
their final version as they type!

We'll start with an out-of-the-box Rails installation that utilizes
Turbo Drive, Turbo Streams, and Stimulus to then progressively enhance
concepts and tools that are built directly into browsers. Plus, it'll
degrade gracefully when JavaScript is unavailable!

The code samples contained within omit the majority of the application's
setup. While reading, know that the bulk of the application's code was
generated by a `rails new` command

The rest of the source code from this article can be found [on
GitHub][].

[Hotwire]: https://hotwired.dev
[Rails 7]: https://edgeguides.rubyonrails.org/7_0_release_notes.html
[default JavaScript framework]: rails/rails#42999
[on GitHub]: https://github.com/thoughtbot/hotwire-example-template/commits/hotwire-example-live-preview

Drafting Articles
===

We'll start by using Rails `model` generator to create some `Article`
[scaffolding][] code to serve as a starting point for our extensions and
customizations:

```sh
bin/rails generate scaffold Article content:text
bin/rails db:migrate
```

We won't be making any changes to the vast majority of the generated code, but
there are two view partials that will be changed the most throughout the rest of
the article. To have context for those changes, it's worth becoming familiar
with them before we get started: `app/views/articles/_form.html.erb` and
`app/views/articles/_article.html.erb`.

The `articles/form` partial renders a single `<textarea>` field for our
`Article` model's `content`, along with an `<input type="submit">`
element:

```erb
<%= form_with(model: article) do |form| %>
  <% if article.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(article.errors.count, "error") %> prohibited this article from being saved:</h2>

      <ul>
        <% article.errors.each do |error| %>
          <li><%= error.full_message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= form.label :content %>
    <%= form.text_area :content %>
  </div>

  <div class="actions">
    <%= form.submit %>
  </div>
<% end %>
```

Similarly, the `articles/article` partial renders the value of the
`content` as plain text:

```erb
<div id="<%= dom_id article %>" class="scaffold_record">
  <p>
    <strong>Content:</strong>
    <%= article.content %>
  </p>

  <p>
    <%= link_to "Show this article", article %>
  </p>
</div>
```

The rest of the generated code serves as the foundation for creating,
reading, updating, and destroying `Article` instances. While it's
crucial, they're implementation details that we can ignore for the sake
of this example.

[scaffolding]: https://edgeguides.rubyonrails.org/getting_started.html#mvc-and-you-generating-a-model
seanpdoyle added a commit to thoughtbot/hotwire-example-template that referenced this pull request Feb 25, 2022
The upcoming [Rails 7][] release will be notable for numerous reasons.
One of the more remarkable being the deprecation and removal of Rails
UJS, and the introduction of [Hotwire][] as Rails' [default JavaScript
framework][].

Let's learn more about how Hotwire fits into Rails by building an
Article drafting experience that provides end-users with a preview of
their final version as they type!

We'll start with an out-of-the-box Rails installation that utilizes
Turbo Drive, Turbo Streams, and Stimulus to then progressively enhance
concepts and tools that are built directly into browsers. Plus, it'll
degrade gracefully when JavaScript is unavailable!

The code samples contained within omit the majority of the application's
setup. While reading, know that the bulk of the application's code was
generated by a `rails new` command

The rest of the source code from this article can be found [on
GitHub][].

[Hotwire]: https://hotwired.dev
[Rails 7]: https://edgeguides.rubyonrails.org/7_0_release_notes.html
[default JavaScript framework]: rails/rails#42999
[on GitHub]: https://github.com/thoughtbot/hotwire-example-template/commits/hotwire-example-live-preview

Drafting Articles
===

We'll start by using Rails `model` generator to create some `Article`
[scaffolding][] code to serve as a starting point for our extensions and
customizations:

```sh
bin/rails generate scaffold Article content:text
bin/rails db:migrate
```

We won't be making any changes to the vast majority of the generated code, but
there are two view partials that will be changed the most throughout the rest of
the article. To have context for those changes, it's worth becoming familiar
with them before we get started: `app/views/articles/_form.html.erb` and
`app/views/articles/_article.html.erb`.

The `articles/form` partial renders a single `<textarea>` field for our
`Article` model's `content`, along with an `<input type="submit">`
element:

```erb
<%= form_with(model: article) do |form| %>
  <% if article.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(article.errors.count, "error") %> prohibited this article from being saved:</h2>

      <ul>
        <% article.errors.each do |error| %>
          <li><%= error.full_message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= form.label :content %>
    <%= form.text_area :content %>
  </div>

  <div class="actions">
    <%= form.submit %>
  </div>
<% end %>
```

Similarly, the `articles/article` partial renders the value of the
`content` as plain text:

```erb
<div id="<%= dom_id article %>" class="scaffold_record">
  <p>
    <strong>Content:</strong>
    <%= article.content %>
  </p>

  <p>
    <%= link_to "Show this article", article %>
  </p>
</div>
```

The rest of the generated code serves as the foundation for creating,
reading, updating, and destroying `Article` instances. While it's
crucial, they're implementation details that we can ignore for the sake
of this example.

[scaffolding]: https://edgeguides.rubyonrails.org/getting_started.html#mvc-and-you-generating-a-model
dskecse added a commit to dskecse/dotfiles that referenced this pull request Jan 9, 2023
dskecse added a commit to dskecse/dotfiles that referenced this pull request Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants