Hi All,
Thanks for you suggestions, even the RTFM ones. I tried two
suggestions, and here are my results. Please excuse the line
wrapping, I copied and pasted directly from the ''rake routes''
output.
As you can see below, both suggestions result in mapping the desired
''publish'' action into the id parameter of an existing action
with a
similar route. This is not what I want. I guess I will have to hand-
code the entire set of routes, I had hoped a way of extending a
resource would be DRYer, but apparently not. Any other suggestions?
(1) routes.rb entry:
map.resources :document_clients, :new => { :publish => :put }
rake routes output:
publish_new_document_client PUT /document_clients/new/publish
(.:format) {:controller=>"document_clients",
:action=>"publish"}
new_document_client GET /document_clients/new
(.:format) {:controller=>"document_clients",
:action=>"new"}
edit_document_client GET /document_clients/:id/edit
(.:format) {:controller=>"document_clients",
:action=>"edit"}
document_client GET /document_clients/:id
(.:format) {:controller=>"document_clients",
:action=>"show"}
PUT /document_clients/:id
(.:format)
{:controller=>"document_clients", :action=>"update"}
DELETE /document_clients/:id
(.:format)
{:controller=>"document_clients", :action=>"destroy"}
actual behavior of controller:
document_clients_controller#new action invoke, with :id =>
''publish''
#not what I wanted
(2) routes.rb entry:
map.resources :document_clients, :collection => { :publish => :put }
publish_document_clients PUT /document_clients/publish(.:format)
{:controller=>"document_clients", :action=>"publish"}
document_clients GET /document_clients(.:format)
{:controller=>"document_clients", :action=>"index"}
POST /document_clients(.:format)
{:controller=>"document_clients", :action=>"create"}
new_document_client GET /document_clients/new(.:format)
{:controller=>"document_clients", :action=>"new"}
edit_document_client GET /document_clients/:id/edit(.:format)
{:controller=>"document_clients", :action=>"edit"}
document_client GET /document_clients/:id(.:format)
{:controller=>"document_clients", :action=>"show"}
PUT /document_clients/:id(.:format)
{:controller=>"document_clients", :action=>"update"}
DELETE /document_clients/:id(.:format)
{:controller=>"document_clients", :action=>"destroy"}
document_clients_controller#show, with :id => ''publish'' #
again, not
what I wanted
On Nov 13, 8:09 pm, John Tajima
<johntaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> In your routes.rb:
>
> map.resources :document, :collection => { :publish => :post }
>
> and add your
>
> def publish
> ..
> end
>
> in your controller.
>
> On Nov 13,
12:30 pm,explainer<keburg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
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
> > 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.