# REST and extra actions

**URL:** <https://www.ruby-forum.com/t/rest-and-extra-actions/144258>\
**Category:** Rails\
**Created:** [July 27, 2008, 8:15pm UTC](https://www.ruby-forum.com/t/rest-and-extra-actions/144258 "2008-07-27T20:15:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![roa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e7dd6/32.png) [@roa](https://www.ruby-forum.com/u/roa)\
**Post date:** [July 27, 2008, 8:15pm UTC](https://www.ruby-forum.com/t/rest-and-extra-actions/144258/1 "2008-07-27T20:15:38Z")

</div>

Hi,

I’m trying to implement some charts in my REST application. But I can’t  
seem to use an extra action like “chart” in my controller. Becouse of  
the rest approach, it sees the action name as an id.

Does anyone know how to overcome this? So that I can visit the charts  
page of a sertain resource like /resource/charts ?

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![roa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e7dd6/32.png) [@roa](https://www.ruby-forum.com/u/roa)\
**Post date:** [July 27, 2008, 8:26pm UTC](https://www.ruby-forum.com/t/rest-and-extra-actions/144258/2 "2008-07-27T20:26:22Z")

</div>

define your routes like this:

map.resources :payments, :collection =\> [:export\_paypal], :member =\>  
[:print\_pdf]

the difference between collection & member is, that collections  
work on all items of that resource (no id needed, like index action),  
so

export\_paypal\_payments\_path()

could be used and give you a list of all payments

while a member works on a single item of the resource, defined by it’s  
id

print\_pdf\_payment\_path(1234)

would print the payment with id 1234 as pdf

of course like with all other REST actions (or CRUD actions, to be  
correct)  
you can use additional named params like:

export\_paypal\_payments\_path(:type =\> :monthly)  
print\_pdf\_payment\_path(1234, :font =\> “Arial”)

---

<div class="post-metadata">

**Author:** ![roa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e7dd6/32.png) [@roa](https://www.ruby-forum.com/u/roa)\
**Post date:** [July 27, 2008, 9:29pm UTC](https://www.ruby-forum.com/t/rest-and-extra-actions/144258/3 "2008-07-27T21:29:33Z")

</div>

Thorsten M. wrote:

> you can use additional named params like:
> 
> export\_paypal\_payments\_path(:type =\> :monthly)  
> print\_pdf\_payment\_path(1234, :font =\> “Arial”)

Thank you Thorsten for your quick reply. You answer helped me a lot.

One small question regarding the additional parameters, do I need to  
declare this somewhere in the routes files?

Thank you again for the help

---

<div class="post-metadata">

**Author:** ![roa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e7dd6/32.png) [@roa](https://www.ruby-forum.com/u/roa)\
**Post date:** [July 28, 2008, 1:09pm UTC](https://www.ruby-forum.com/t/rest-and-extra-actions/144258/4 "2008-07-28T13:09:37Z")

</div>

> One small question regarding the additional parameters, do I need to  
> declare this somewhere in the routes files?

No, whatever you use like

export\_paypal\_payments\_path(:type =\> :monthly)

will just end up as params[:type] in your controller
