Routes problem

Hello all,
Here's a newbie question (4 weeks and counting).
My routes.rb is as below.

map.resources :projects, :departments, :users, :admins, :imports, :notes

#Below is route in question
map.resources :projects, :collection => { :view_all => :get }

map.home '', :controller => 'projects', :action => 'index'
map.connect ':controller/:action/:id.:format'
map.connect ':controller/:action/:id'

I'm tried to get a url like this:
http://localhost:3000/projects/view_all

I have a view_all in the ProjectsController and I have a view_all
template.

When I type in the desired url, I get this error:

"ActiveRecord::RecordNotFound in ProjectsController#show

Couldn't find Project with ID=view_all"

Thank you for any help.

JohnM

ROR will attempt to find routes from the top of the file first and then move on to the rest of the file. It would seem that you have listed projects twice:
map.resources :projects, :departments, :users, :admins, :imports, :notes
#Below is route in question
map.resources :projects, :collection => { :view_all => :get }

The first one (without the :collection) would be used.

Hope this helps.

Another tip is to run "rake routes" to see all the available routes.

Hello all,
Here's a newbie question (4 weeks and counting).
My routes.rb is as below.

map
.resources :projects, :departments, :users, :admins, :imports, :notes

#Below is route in question
map.resources :projects, :collection => { :view_all => :get }

Routes have preference based on their order of appearance. The first time you create routes for :projects, there's a show route like /projects/:id and that matches before the second one.

Combine those into:

map.resources :projects, :collection => { :view_all => :get }
map.resources :departments, :users, :admins, :imports, :notes

HOWEVER, the regular route:
  /projects
is normally going to show you all the projects anyway.

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com

Since I've been learning rails, I thought that routes are the linking of
the "Controller" Object to their "Action" method.
When you set up RESTful routing, you need to add custom or named routes
after the default 7.
To set up custom or named routes, you use "map.connect" "path/to/view",
:controller => 'controller', :aciton => 'action'

Is this correct or am I lost?

Rob Biedenharn wrote:

Hi John,
try this approach:
in the Product class add this function-

require ‘uri’
def self.find_custom arg
object = self.new
object.id = URI.escape(arg)
object
end

and in the controller try calling as:
Product.find_custom(params[:id]).view_all

just try it, and let me know.

Since I've been learning rails, I thought that routes are the
linking of the "Controller" Object to their "Action" method.
When you set up RESTful routing, you need to add custom or named
routes after the default 7.
To set up custom or named routes, you use "map.connect" "path/to/
view",
:controller => 'controller', :aciton => 'action'

Is this correct or am I lost?

Not lost, just not yet there. As you've no doubt seen from other
responses, you had :projects in BOTH places. Personally, I never
define more than one resource route at a time.

map.resources :projects, :collection => { :view_all => :get }
map.resources :departments
map.resources :users
map.resources :admins
map.resources :imports
map.resources :notes

If you need to add other routes to them, you'll need to pull separate
them anyway.

-Rob

This code is so messed up it's almost not even wrong. What exactly is
it supposed to do?

--Matt Jones