0

I'm tweaking some scaffold templates for an app so I mostly just want to copy the built-in/default templates. My question is what is the process I can follow to locate the templates?

For example, thanks to the helpful answers of Tim Krins I now know to look in:

  • cd $(bundle show railties)/lib/rails/generators/rails/scaffold_controller/templates/ for controller templates (reference)
  • cd $(bundle show activerecord)/lib/rails/generators/active_record/model/templates/ for model templates (reference)

I also managed to combine his bundle show <gem> tip with spelunking through Github issues in haml-rails to figure out the path for HAML templates is:

  • cd $(bundle show haml-rails)/lib/generators/haml/scaffold/templates

I haven't yet been able to use that knowledge to figure out the general solution though so next time I'll have to search StackOverflow again.

How would I go about figuring out for myself the template locations for various test files (without telling you which testing framework I'm using)? How would I locate the templates used for the invoke resource_route step?

  1. How do I figure out which gem to look in? (e.g. How could I have figured out railties vs activerecord above?)
  2. How do I figure out what path to look in? (e.g. How would I know to look in activerecord/.../activerecord but railties/.../rails?)
Matthew
  • 1,300
  • 12
  • 30

1 Answers1

0

Which gem are you trying to change?

What is needed in the case of the Devise or Spree gems is to recreate the filepath within the app directory, then copy/clone the erb/haml file from the gem's github repo, and make your changes in the local file.

There is a gem called Deface which can allow you to edit specific html components in views without recreating the entire view. This is a more complex but ultimately more maintainable path - depending on the extent of your changes.

kykyi
  • 375
  • 4
  • 10
  • Thanks for the answer but I'm specifically not looking for the answer to "how do I obtain templates for gem XYZ?"... I'd like to learn how to fish for myself and figure out A) how to locate the templates for any gem and B) how to figure out the correct local templates path to put them in. Thanks for the link to Deface, I'll see if it can guide me in the right direction – Matthew Jan 06 '21 at 07:53