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?
Asked
Active
Viewed 1.4k times
3 Answers
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.
![](../../users/profiles/6068.webp)
pupeno
- 256,034
- 114
- 324
- 541
-
2admin/blog works slightly better for me, but it's only a little and quite possibly totally subjective. – ere Mar 21 '12 at 17:06
-
11in Rails >3 `rails g scaffold admin/blog` – Anatoliy Kukul Jun 20 '13 at 04:47
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
![](../../users/profiles/3834822.webp)
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.
![](../../users/profiles/292956.webp)
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