21

I want to generate the scaffold in a Rails app, generating the model as usual but having the controller inside the admin namespace. Is it possible?

pupeno
  • 256,034
  • 114
  • 324
  • 541

3 Answers3

19

The first time I've done it, I run

script/generate scaffold blog

and then refactored the controller, views, etc. My prefered solution at the moment is:

script/generate scaffold admin::blog

and then refactor the model, unit test and migration; it's less work.

If there's a better answer, I'll accept it.

pupeno
  • 256,034
  • 114
  • 324
  • 541
6

You can do this for rails < 3:

script/generate scaffold Blog title:string

or

script/generate scaffold admin::blog title:string

For rails > 3:

rails g scaffold Blog title:string

or

rails g scaffold admin/blog title:string
ilgam
  • 3,186
  • 1
  • 28
  • 25
4

This question is pretty widely asked on stackoverflow. And I also faced this problem and found no standard solution for that.

So, I created rails-admin-scaffold gem (for now it's Rails 4 only) which automates this process and wrote an article with more detailed explanation. Hope it would be helpful for someone.

dhampik
  • 144
  • 3
  • 4
  • @ArnoldRoa I also encountered such issue. If there's a model called Admin, then it is impossible to have `Admin` namespace -- because rails would namespace it with a module with same name -- therefore, it would be a name conflict. – songyy Jul 23 '15 at 14:27