Customizing output destinations and contents such as javascript generated by scaffold

Asked 2 months ago, Updated 2 months ago, 2 views

How do I customize the javascript and stylesheet output destinations, file names, and contents?

I would like to change the output destination as follows.

app/assets/javascripts/items.js

app/javascript/packs/items/[index show new edit].js

app/assets/stylesheets/moves.css

app/javascript/app-style/items/[index show new edit].sass

ruby-on-rails

2022-09-30 11:39

1 Answers

Changing the contents of a file is simple.

 rails app:templates:copy
(rake rails:templates:copy for Rails 5 and earlier)

This will copy the template file to lib/templates, so please edit it.

It is a little difficult to rewrite the output destination.You must customize the behavior of the generator.There's a mechanism in place, but it's a little hard to explain the steps from scratch, so see Rails guide.

There are two possible policies.

  • Replace the generator itself
  • Once the original generator has been moved, the generator that copies, moves, and rewrites files


2022-09-30 11:39

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.