Rest, routes, path_prefix and default params

I am trying to use routes with default params to have routes
‘/mycompany/departments’
and
‘/companies/1/departments’

mean the same thing (both restful routes).

When I set up the files as below, I get an error of
‘Couldn’t find Company without an ID’

and my log file shows the following …

Processing DepartmentsController#index (for 127.0.0.1 at 2006-08-14
14:00:34) [GET]
Session ID: d88710b06b66529459bc8c9c625109fc
Parameters: {“action”=>“index”, “controller”=>“departments”}

How can I use restful routes with default parameters?

***** routes.rb *******
ActionController::Routing::Routes.draw do |map|

map.resources :departments, :path_prefix => ‘mycompany’,:company_id => 1

map.resources :companies do |companies|
companies.resources :departments do |departments|
departments.resources :departments, :name_prefix => ‘child_’
end
end

Install the default route as the lowest priority.

map.home ‘’, :controller => ‘companies’,:action => ‘index’
map.connect ‘:controller/:action/:id’, :id => nil, :action => ‘index’

end

in application.rb, I have

class ApplicationController < ActionController::Base

protected

def find_company
@company = Company.find(params[:company_id])
end

end

And in departments_controller.rb

class DepartmentsControler < ActionController::Base

before_filter :find_company

end

In companies_controller.rb

I have

class CompaniesController < ActionController::Base

protected

def find_company
@company = Company.find(params[:id])
end

end

On 8/14/06, Dominic S. [email protected] wrote:

and my log file shows the following …

map.connect ‘:controller/:action/:id’, :id => nil, :action => ‘index’
@company = Company.find(params[:company_id])
end
@company = Company.find(params[:id])
end

end


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Dominic,
From looking at the source, it doesn’t appear that map.resources
supports default parameters.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs