ElMassimo / ElMassimo/vite-plugin-erb
Clarification about .js.erb disclaimer when sent by controller (`respond_to`) (AJAX)
- Dominant language
- TypeScript
- Stars
- 11
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
In the Readme, you write
> Using ERB with JS and CSS files can lead to a fragile setup where your frontend assets are entangled with your backend setup, making it very hard to migrate to different tooling or frameworks.
> The goal of this library is to ease out the transition as you gradually remove your `.js.erb` files.
But am I right, that this advice only concerns "standalone" `.js.erb` assets, and _not_ the ones rendered by your controller methods? E.g. via
```rb
# some_ruby_controller.rb
@posted = false
respond_to do |format|
format.js { render :my_js_sent_by_controller}
end
```
For example, in those files, we want to check global variables set by the controller action, e.g. via
```js
// my_js_sent_by_controller.js.erb
const posted = <%= @posted %>
if (posted) { ... }
```
and based on this do different things in the frontend after a user has triggered a controller action (e.g. via a button click). Or would you consider this an anti-pattern as well? But how would one counteract this? I don't see how [JS From Routes](https://js-from-routes.netlify.app/) could help in this case. Are `.js.erb` really that bad in the end?
Contributor guide
Assessment
This issue has not been assessed yet.