# How to extend a RESTful route?

**URL:** <https://www.ruby-forum.com/t/how-to-extend-a-restful-route/178939>\
**Category:** Rails\
**Created:** [November 13, 2009, 8:23pm UTC](https://www.ruby-forum.com/t/how-to-extend-a-restful-route/178939 "2009-11-13T20:23:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![explainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbce88/32.png) [@explainer](https://www.ruby-forum.com/u/explainer)\
**Post date:** [November 13, 2009, 8:23pm UTC](https://www.ruby-forum.com/t/how-to-extend-a-restful-route/178939/1 "2009-11-13T20:23:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![explainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbce88/32.png) [@explainer](https://www.ruby-forum.com/u/explainer)\
**Post date:** [November 13, 2009, 8:24pm UTC](https://www.ruby-forum.com/t/how-to-extend-a-restful-route/178939/2 "2009-11-13T20:24:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![explainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbce88/32.png) [@explainer](https://www.ruby-forum.com/u/explainer)\
**Post date:** [November 14, 2009, 5:32am UTC](https://www.ruby-forum.com/t/how-to-extend-a-restful-route/178939/3 "2009-11-14T05:32:11Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![explainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbce88/32.png) [@explainer](https://www.ruby-forum.com/u/explainer)\
**Post date:** [November 14, 2009, 12:01pm UTC](https://www.ruby-forum.com/t/how-to-extend-a-restful-route/178939/4 "2009-11-14T12:01:57Z")

</div>

In your routes.rb:

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

and add your

def publish  
…  
end

in your controller.

---

<div class="post-metadata">

**Author:** ![explainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbce88/32.png) [@explainer](https://www.ruby-forum.com/u/explainer)\
**Post date:** [November 16, 2009, 5:36am UTC](https://www.ruby-forum.com/t/how-to-extend-a-restful-route/178939/5 "2009-11-16T05:36:30Z")

</div>

Hi  
To get a better understanding read

> **[Rails Routing from the Outside In — Ruby on Rails Guides](https://guides.rubyonrails.org/routing.html)**
>
> Rails Routing from the Outside InThis guide covers the user-facing features of Rails routing.After reading this guide, you will know: How to interpret the code in config/routes.rb. How to construct your own routes, using either the preferred...

Sijo
