How do I add an extra parameter to a REST action?

In routes.rb:

map.resources :games

I can do something like this:

games_path(:sport => 'hockey')

which results in a path like "/games?sport=hockey". Awesome.

But elsewhere I have a similar situation where I want to do that to a specific game instance:

game_path(@game, :cancelled => 'true'), :method => :put

The idea is that the user clicks a link to cancel the game. I'm using the :put method to invoke the update action, but please note that I'm not just updating an attribute in the model - it's telling the controller what needs to be done (basically call the @game.cancel method, which will run a bunch of business logic).

However, using that syntax doesn't work:

You have a nil object when you didn't expect it! The error occurred while evaluating nil.to_sym

I could put custom actions on the resource, using :member => { :cancelled => :put }, but I might end up with ten different actions, so this doesn't seem like the right approach.

Any ideas?

Thanks! Jeff

Hi Jeff,

comments below:

In routes.rb:

map.resources :games

I can do something like this:

games_path(:sport => 'hockey')

which results in a path like "/games?sport=hockey". Awesome.

But elsewhere I have a similar situation where I want to do that to a specific game instance:

game_path(@game, :cancelled => 'true'), :method => :put

you can use game_path(:id => @game, :cancelled => true) instead.

Alternatively, one of the features of my resource_fu plugin is being
able to use that exact syntax. See:

http://agilewebdevelopment.com/plugins/resource_fu for more info.

HTH, Trevor

Thanks, Trevor! That worked great.

Jeff