开发者

Rails Building a Admin Console for Application

First of all i have followed the Agile Web Development with Rails Third Edition Book. However i would like to be able to create a admin part of the application. There is one to a degree and as i have the following:

Controller Admin

Login, Logout, Index

Controller Products

I would like to create a section in the Admin Controller to control the products. I have tried looking around on the net and playing around on the system. But i am getting a confused on the issue.

I tried creating a Products pages in the in the Admin/Views folder. This allows me to View the products at the following: //localhost/admin/products. This is great but if i want to edit and create products i would like //localhost/admin/products/:id/edit etc. a开发者_开发百科nd edit and etc can only happen within the admin URl.

working with Rails 2.0.2

Thanks in advance


You really want to be using a later version of Rails than 2.0.2 if you are able to - 2.3.14 is latest in the v2 and v3.1.0 actually came out not very long ago.

To answer your question you want to be looking into route namespacing which allow you to group routes/resources together inside a namespace, eg admin.

namespace :admin do
  root :to => 'admin#index' #Default route for when you got to /admin
  resources :products

This last route will create all 7 restful routes for your products model inside the /admin namespace. You will want a controller named app/controllers/admin/products_controller.rb where you will have the index, create, update...etc methods and corresponding views in app/views/admin/views/productions


You can use namespace for this. In your routes.rb:

map.namespace(:admin) do |admin|
admin.resources :products
end

and then, generate admin/products controller and use with REST:

script/generate controller admin/products


admin_products_path
edit_admin_products_path(product.id)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜