Currently I am working on a blog engine in RoR and I encounter severa issues with routing.
The routes.rb looks like this:
match '/admin', :to => 'posts#new'
match '/get/:id', :to => 'posts#get'
match '/new', :to => 'posts#new'
delete '/:id', :to => 'posts#destroy'
post '/edit/:id', :to => 'posts#update'
put '/edit/:id', :to => 'posts#update'
get '/edit/:id', :to => 'posts#new', :as => 'post'
get '/:slug', :to => 'posts#show', :as => 'post'
root :to => 'posts#index'
and I would like to transform it in something like:
resources :admin do
resources :posts
end
Any help would be very appreciated.
A bit more information is needed. What do you want to place in the admin resource? Only posting, or also editing?
But a few tips to get started:
– You have to split your posts-controller. Make a subfolder in the controllers called admin (the resource name). Move the admin-functions to this controller, and leave the public posts-function (index and show) in the normal posts_controller.
– Do the same for the views.
And, i suspect you want the routes to be:
Then you can put some form of authentication to the admin namespace.
Hope this helps you on the way.