0

I want to generate scaffold with a custom namespace but I want it to use an existing model/table.

If I generate a scaffold like this it generate scaffold with a custom namespace but use a new table admin_locations :

rails generate scaffold Admin::Location

Is there a way to do the same thing but using the existing Location model and locations table ?

Nino
  • 1,167
  • 1
  • 7
  • 13
  • 1
    That is not really the purpose of scaffolding you could just generate the controllers and the views though `rails g controller Admin::Locations new create edit index destroy` You will have to add the appropriate routes though. – engineersmnky Apr 24 '18 at 19:52
  • @engineersmnky I was looking for a lazy-way to create the views, but I guess I could this and just copy paste the views from a blank CRUD project – Nino Apr 24 '18 at 19:58
  • They won't have content, only the default notice `

    Admin::Locations#index

    ....`
    – Nino Apr 24 '18 at 20:05
  • Very true but scaffolded views are extremely simplistic with the intention of them being modified – engineersmnky Apr 24 '18 at 20:11

1 Answers1

0

As suggested by @engineersmnky the best way to do this is :

rails g controller Admin::Locations new create edit index destroy

Then I suggest to create a blank rails project and do :

rails g scaffold Admin::Location

After this you can replace views by the ones generated on the newly created app (/app/views/admin/locations)

Maybe there is a better solution, I would love to know if it's the case !

Nino
  • 1,167
  • 1
  • 7
  • 13