Scaffolding: Create, Edit, Destroy in admin area

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 and the
admin area by 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

=== 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

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

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

I wrote a guide on doing exactly that: http://frozenplague.net/2008/03/16/administration-namespacing/

May also help out.

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

Completely forgot about that one! Completely right Gabriel.

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

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