# Scaffolding: Create, Edit, Destroy in admin area

**URL:** <https://www.ruby-forum.com/t/scaffolding-create-edit-destroy-in-admin-area/141902>\
**Category:** Rails\
**Created:** [July 1, 2008, 4:32pm UTC](https://www.ruby-forum.com/t/scaffolding-create-edit-destroy-in-admin-area/141902 "2008-07-01T16:32:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![christoph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@christoph](https://www.ruby-forum.com/u/christoph)\
**Post date:** [July 1, 2008, 4:32pm UTC](https://www.ruby-forum.com/t/scaffolding-create-edit-destroy-in-admin-area/141902/1 "2008-07-01T16:32:35Z")

</div>

Hi Community,  
I’m currently trying to create a blog software in rails, but I’ve got  
a problem:  
I generated scaffolding for my articles and only want administrators  
to write, edit or delete articles. So I wanted to move this parts to  
another, secured controller. The one controller to display articles is  
called articles :), the other is also called articles, but is located  
in a folder called “admin”. The code looks like this:  
Admin::ArticlesController \< ApplicationController. This works great. I  
can view the public area by [http://localhost:3000/articles](http://localhost:3000/articles) and the  
admin area by [http://localhost:3000/admin/articles](http://localhost:3000/admin/articles). But I’ve got  
problems with the routing: The named routes (?) generated by  
map.resources :articles (e.g. edit\_article\_path(article),  
new\_article\_path, and so on…) still point to the “public area”,  
whereas the actions aren’t there. I think it’s pretty a newbie  
question, but how can I generate different routes so that these routes  
don’t point to the “public area”.

Thank you very much in advance  
Christoph

---

<div class="post-metadata">

**Author:** ![christoph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@christoph](https://www.ruby-forum.com/u/christoph)\
**Post date:** [July 1, 2008, 4:46pm UTC](https://www.ruby-forum.com/t/scaffolding-create-edit-destroy-in-admin-area/141902/2 "2008-07-01T16:46:07Z")

</div>

=== routes.rb

map.namespace :admin do |admin|  
admin.resources :articles  
end

then in your admin views you change your links like such:

article =\> admin\_article\_url(article)  
edit\_article\_path(article) =\> edit\_admin\_article\_url(article)

the same methodology with paths.

also check that the redirections from the controller are changed as  
well.  
Namely in the create, update and destoy.

hope this helps

---

<div class="post-metadata">

**Author:** ![christoph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@christoph](https://www.ruby-forum.com/u/christoph)\
**Post date:** [July 1, 2008, 7:44pm UTC](https://www.ruby-forum.com/t/scaffolding-create-edit-destroy-in-admin-area/141902/3 "2008-07-01T19:44:29Z")

</div>

Thank you very much for your quick and great help. That was exactly  
what I was looking for 🙂

Christoph

---

<div class="post-metadata">

**Author:** ![christoph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@christoph](https://www.ruby-forum.com/u/christoph)\
**Post date:** [July 1, 2008, 11:56pm UTC](https://www.ruby-forum.com/t/scaffolding-create-edit-destroy-in-admin-area/141902/4 "2008-07-01T23:56:46Z")

</div>

On Tue, Jul 1, 2008 at 7:43 PM, Christoph [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Thank you very much for your quick and great help. That was exactly  
> what I was looking for 🙂
> 
> Christoph

And in your forms, instead of marking :

\<% form\_for(@article) do |f| %\>

# form…

\<% end %\>

you can use

\<% form\_for([:admin, @article]) do |f| %\>

# form…

\<% end %\>

to link to the correct action

–  
Gabriel L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![christoph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@christoph](https://www.ruby-forum.com/u/christoph)\
**Post date:** [July 2, 2008, 2:49pm UTC](https://www.ruby-forum.com/t/scaffolding-create-edit-destroy-in-admin-area/141902/5 "2008-07-02T14:49:59Z")

</div>

Ryan,  
You need to check out your site. This is the second time I’ve clicked  
on a link you’ve promoted and there is simply a title with a blank  
page.  
Kathleen

---

<div class="post-metadata">

**Author:** ![christoph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@christoph](https://www.ruby-forum.com/u/christoph)\
**Post date:** [July 2, 2008, 4:26pm UTC](https://www.ruby-forum.com/t/scaffolding-create-edit-destroy-in-admin-area/141902/6 "2008-07-02T16:26:46Z")

</div>

On Jul 1, 9:07 pm, “Gabriel L.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<% end %\>
> 
> to link to the correct action

Completely forgot about that one! Completely right Gabriel.

---

<div class="post-metadata">

**Author:** ![christoph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@christoph](https://www.ruby-forum.com/u/christoph)\
**Post date:** [July 2, 2008, 3:43am UTC](https://www.ruby-forum.com/t/scaffolding-create-edit-destroy-in-admin-area/141902/7 "2008-07-02T03:43:46Z")

</div>

I wrote a guide on doing exactly that:

> **[frozenplague.net](http://frozenplague.net/2008/03/16/administration-namespacing/)**
>
> This domain may be for sale!

May also help out.

---

<div class="post-metadata">

**Author:** ![christoph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@christoph](https://www.ruby-forum.com/u/christoph)\
**Post date:** [July 3, 2008, 4:15pm UTC](https://www.ruby-forum.com/t/scaffolding-create-edit-destroy-in-admin-area/141902/8 "2008-07-03T16:15:44Z")

</div>

You can only write this and still nothing else renaming or writing.

map.namespace :admin do |admin|  
map.resources :article, :controller =\> ‘admin/  
article’, :path\_prefix =\> ‘admin’  
end

---

<div class="post-metadata">

**Author:** ![christoph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@christoph](https://www.ruby-forum.com/u/christoph)\
**Post date:** [July 2, 2008, 4:26pm UTC](https://www.ruby-forum.com/t/scaffolding-create-edit-destroy-in-admin-area/141902/9 "2008-07-02T16:26:46Z")

</div>

> Ryan,  
> You need to check out your site. This is the second time I’ve clicked  
> on a link you’ve promoted and there is simply a title with a blank  
> page.

Works fine for me
