0

Instead of starting a new rails app from scratch, I built it from a template (that automatically generates the User table with various things already set up - login/password reset, a few other things).

If I want to achieve the effect of rails g scaffold User .. but without overwriting anything that's already been set up (via the template), is there any easy way to do that? That is, rails g scaffold User should only add to code / files / columns, but not overwrite anything.

Is there any easy way to do this?

Anand Bait
  • 331
  • 1
  • 12
stevec
  • 41,291
  • 27
  • 223
  • 311
  • Yes, you can add an option to only generate a controller or a view, etc.. See https://www.rubyguides.com/2020/03/rails-scaffolding/ generating specific components. – dbugger Aug 15 '20 at 15:18
  • This is a little confusing. It will generate all the same files you already have. What is new that you want to include? If you just need to update the User to have extra columns in the DB or something that is done via a migration. It would help to know what you want to change specifically, not a general statement of just wanting to run the command again (it does ask if you want to override and you can choose yes or no) – Rockwell Rice Aug 18 '20 at 00:10
  • @RockwellRice Basically I started a started a new app from a template which did a bunch of configs for me, but then I wanted to generate a user scaffold and wasn't sure if that would keep in place or overwrite the existing user files. In the specific template, it had user model setup (via devise), but not other things like controllers etc. I was hoping there was some way to merge the two but (critically) without losing any of the existing code. – stevec Aug 18 '20 at 00:14
  • 1
    You can run `rails g` for just models, or controllers as well. But if Devise is being used you like would likely need to generate and update those controllers if you wanted to add new functionality. I do not think the scaffold would solve your issue based on what you describe. – Rockwell Rice Aug 18 '20 at 02:27
  • @RockwellRice after realising the devise setup didn't generate a User controller (only a model), I realised this is the solution: https://stackoverflow.com/questions/4333393/how-to-run-rails-generate-scaffold-when-the-model-already-exists – stevec Aug 19 '20 at 11:19
  • You can generate the devise controller and add in the behavior you need – Rockwell Rice Aug 19 '20 at 13:02

0 Answers0