Confused newbe again.. with id instead of action in URL

Hi,

I'm trying to generate a new action and is very confused by the error message I get. I am accessing http://localhost:3001/members/isactive/ and get this error message:

ActiveRecord::RecordNotFound in MembersController#show

Couldn't find Member with ID=isactive

How come? Shouldn't I get the isactive action + view?

/Fredrik

Frerik,

We can't see the web server running on your local machine (localhost: 3001). You'll need to provide a code sample....

Ken

you’re using restful routing and you haven’t set up a route for isactive yet.

Hi,

Ok, this may very well be a routing problem, but I fail to do something about it. My config/routes.rb contained just the default

ActionController::Routing::Routes.draw do |map|   map.resources :members

  map.resources :members   map.connect ':controller/:action/:id'   map.connect ':controller/:action/:id.:format'

end

which does not seem to include my case. But, how do I fix this? Adding map.connect ':controller/:action' either above or below the last default cases does nothing, and I cannot get an explicit

map.connect 'members/inactive', :controller => 'members', :action => 'inactive'

to get me anywere. RoR wants to map the last entry to "id" rather than action.

BTW, adding a fake ID, as in http://localhost:3001/members/inactive/1, works :slight_smile:

/Fredrik

You need to add a custom route. Remove your 'map.resources :members' and replace it with:

map.resources :members, :collection => { :inactive => :any }

replace :any with either :get or :post, depending upon how you want to access it (or leave it as :any to allow either :get or :post)

Exellent!

This did the trick. Now, where do I learn about these new routes?

/Fredrik

You can find RESTful Rails documentation everywhere on the net via google. I found these two PDF documents on it for you:

http://www.b-simple.de/download/restful_rails_en.pdf

the second is a cheatsheet, so it's concise and contains only essential examples