Rails 3.0 Routing..

0 views
Skip to first unread message

Doon

unread,
Jul 9, 2010, 10:10:15 PM7/9/10
to TechValley Ruby Brigade
Just working on a small rails 3 App here, and playing with the new
router, and digging the new syntax...

Power::Application.routes.draw do |map|

resources :outlets , :only=>[:index,:show] do
member do
post :reboot, :on, :off
end
end
end

Wires it up this way..

reboot_outlet POST /outlets/:id/reboot(.:format)
{:controller=>"outlets", :action=>"reboot"}
on_outlet POST /outlets/:id/on(.:format)
{:controller=>"outlets", :action=>"on"}
off_outlet POST /outlets/:id/off(.:format)
{:controller=>"outlets", :action=>"off"}
outlets GET /
outlets(.:format)
{:controller=>"outlets", :action=>"index"}
outlet GET /
outlets/:id(.:format)
{:controller=>"outlets", :action=>"show"}

want to scope your admin stuff under /admin is as easy as..

namespace :admin do
match '/' => 'admin#index', :as=>:home
resources :pdus do
resources :outlets
end
resources :users
end

No real questions or the like, just happy that I hit 20 passing
scenarios on this project, and figured I would share :)

Have a good weekend..
-Doon
Reply all
Reply to author
Forward
0 new messages