How to extend a RESTful route?

I used the scaffold option to generate a RESTful set of routes to a
Document model. All works as described. Now, I wish to extend the
controller to add a ‘publish’ action on DocumentController and add a
‘publish’ route to mimic what the generated ‘create’ action does. How
do I specify this in the routes.rb file? BTW, I need to keep the
create action as generated.

Well, you could add a ‘publish’ action to your Document controller and
add a ‘publish’ route. Have you looked at any Rails tutorials yet?

-eric

On Fri, Nov 13, 2009 at 09:30:05AM -0800, explainer wrote:

I used the scaffold option to generate a RESTful set of routes to a
Document model. All works as described. Now, I wish to extend the

You might need to tweak this, but I think what you need is:

map.login 'publish', :controller => 'documents', :action => 

‘publish’

Other than creating publish() in your documents_controller.rb, you
shouldn’t have to change anything else since you’re just adding a
mapping for a new method.


“Oh, look: rocks!”
– Doctor Who, “Destiny of the Daleks”

In your routes.rb:

map.resources :document, :collection => { :publish => :post }

and add your

def publish

end

in your controller.

Hi
To get a better understanding read

Sijo