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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Trevor Squires
2007-Mar-21 21:59 UTC
Re: How do I add an extra parameter to a REST action?
Hi Jeff, comments below: On 21-Mar-07, at 1:37 PM, Jeff wrote:> > 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> 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 > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 21, 4:59 pm, Trevor Squires <tre...-k8q5a0yEZAgS+FvcfC7Uqw@public.gmane.org> wrote:> 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, > TrevorThanks, Trevor! That worked great. Jeff --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---