Ruby On Rails, Design, Simplicity, Web 2.0, Ajax, Mac and Tons of Pizza.

Mar 09

Nested controller and RESTful routes

Posted by Sandro Paganotti in Ruby on Rails - comments are closed digg this add to delicious

Today I tried to use map.resource function within a nested controller, well my first attempt wasn’t really that successful, I tried with this code:


  map.resources :projects, :controller => "planning/projects"  do |projects|
    projects.resources :resources, :controller => "planning/resources" 
    end
  end

But I obtained a routing error while trying to point the browser to ‘planning/projects’ so, the working solution I found is:


  map.resources :projects, :controller => "planning/projects", :path_prefix => "/planning" do |projects|
    projects.resources :resources, :controller => "planning/resources" 
    end
  end

By using the path_prefix option everything worked fine :-)

Sandro

Post a comment

Categories:

Tags:

Powered by Mephisto, Valid XHTML 1.1, Valid CSS - Supported by Wave Factory