# REST actions changing more than 1 record

**URL:** <https://www.ruby-forum.com/t/rest-actions-changing-more-than-1-record/83489>\
**Category:** Rails\
**Created:** [January 26, 2007, 4:37pm UTC](https://www.ruby-forum.com/t/rest-actions-changing-more-than-1-record/83489 "2007-01-26T16:37:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ed\_Hickey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/258eb7/32.png) [@Ed\_Hickey](https://www.ruby-forum.com/u/Ed_Hickey)\
**Post date:** [January 26, 2007, 4:37pm UTC](https://www.ruby-forum.com/t/rest-actions-changing-more-than-1-record/83489/1 "2007-01-26T16:37:49Z")

</div>

I’m in the process of converting a project to be RESTful (Rails 1.2.1)  
but  
am running into an issue I can’t quite solve (gracefully).  
I have a list of Accounts that all need to be modified in the same way  
(‘paused’) Using the restful routes, I can easily setup a route for  
pausing  
one:

map.resources :accounts, :member =\> { :pause =\> :put }

Though, I’m not sure how to setup a route to for multiple deletions.  
This  
is the only solution I’ve found, though it breaks a few REST  
conventions:

map.pause\_accounts ‘/accounts;pause’, :controller =\> “accounts”,  
:action  
=\> “pause”

I can’t figure out how to force the named route to use the PUT method,  
plus  
I have to hack my ‘pause’ action to accept both a single Account id  
(params[:id]) as well as multiple ids. I’m sure I’m missing something  
simple. I can’t seem to find much helpful documentation or examples.

Anyone?

–  
Ed

---

<div class="post-metadata">

**Author:** ![Ed\_Hickey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/258eb7/32.png) [@Ed\_Hickey](https://www.ruby-forum.com/u/Ed_Hickey)\
**Post date:** [January 26, 2007, 4:45pm UTC](https://www.ruby-forum.com/t/rest-actions-changing-more-than-1-record/83489/2 "2007-01-26T16:45:50Z")

</div>

On 26-Jan-07, at 10:37 AM, Ed Hickey wrote:

> a few REST conventions:  
> Anyone?

Ed, reading your requirement leads me to think that you are missing a  
Model.

The Accounts likely are connected in your domain a belongs\_to  
relationship.

Although I don’t know more, having such a requirement would be an  
indication to me that I’ve not modeled something important.

And having such a relationship would allow you to track the  
transactional info that happens through such a group REST action.

Cheers,  
Jodi  
General Partner  
The nNovation Group inc.  
www.nnovation.ca/blog  
ï¿¼

---

<div class="post-metadata">

**Author:** ![Ed\_Hickey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/258eb7/32.png) [@Ed\_Hickey](https://www.ruby-forum.com/u/Ed_Hickey)\
**Post date:** [January 26, 2007, 5:58pm UTC](https://www.ruby-forum.com/t/rest-actions-changing-more-than-1-record/83489/3 "2007-01-26T17:58:06Z")

</div>

On 1/26/07, Jodi S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Anyone?
> 
> Ed, reading your requirement leads me to think that you are missing a  
> Model.  
> The Accounts likely are connected in your domain a belongs\_to  
> relationship.

Yes, the Accounts belong to User. Although, in this situation, I’m  
working  
on an admin interface. There is a screen of Accounts and the admin has  
the  
ability to manage them all in bulk.

Although I don’t know more, having such a requirement would be an  
indication

> to me that I’ve not modeled something important.

And having such a relationship would allow you to track the  
transactional

> info that happens through such a group REST action.

I’m not sure I follow you. Elaborate?  
I’m running into many obstacles when changing my actions to work in the  
RESTful environment. Mostly things that aren’t standard CRUD actions.  
I  
wish there was more documentation on the new routing and resource  
features!

Thanks for the response.

Ed

Cheers,

---

<div class="post-metadata">

**Author:** ![Ed\_Hickey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/258eb7/32.png) [@Ed\_Hickey](https://www.ruby-forum.com/u/Ed_Hickey)\
**Post date:** [January 26, 2007, 6:31pm UTC](https://www.ruby-forum.com/t/rest-actions-changing-more-than-1-record/83489/4 "2007-01-26T18:31:16Z")

</div>

The idea I was getting at that you likely haven’t modeled, we’ll call  
that relationship “Transaction”.

So:

Users belong\_to Account  
Account has\_many Transactions

but also Account has\_many Transactions, and likely Users

(I likely am not talking the right language for your domain, but you  
should be able to make the translation. You may even need an  
AccountTransaction has\_many to make this work).

So when changes are made to an account, you make it through a  
Transaction model (and REST) If you have different types of bulk  
Transactions, then you may need to pass a Transaction type.

so doing a REST on the Transaction model will act on all the Accounts  
for that User - and when you record the Account changes, you can  
track date/time and other items that can be used for auditing.

Generally REST really works when your data Model is rich (IMO), or  
said another way, you can test your data model through a REST  
implementation. Watching DHH’s presentation on his first thoughts on  
implementing REST you’ll see him run into a wall, and then realize he  
was missing a Model.

Cheers,  
Jodi  
General Partner  
The nNovation Group inc.  
www.nnovation.ca/blog

---

<div class="post-metadata">

**Author:** ![Ed\_Hickey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/258eb7/32.png) [@Ed\_Hickey](https://www.ruby-forum.com/u/Ed_Hickey)\
**Post date:** [January 26, 2007, 7:46pm UTC](https://www.ruby-forum.com/t/rest-actions-changing-more-than-1-record/83489/5 "2007-01-26T19:46:33Z")

</div>

Ed,

If you would like more info on refactoring to REST, check out this  
article by Scotty Raymond (IconBuffet, Blinksale, etc). It is  
available on his site, but I have found this link to be more reliable  
(doh!):

> **[stouset - Overview](https://github.com/stouset)**
>
> stouset has 49 repositories available. Follow their code on GitHub.

One of the things to note is how REST takes a different way of thinking  
about your app. Where before you may have had a login action on some  
account controller, now you might want an object to represent what a  
login does. A login creates a session, so why not have a RESTful  
sessions controller? That is what Scotty has done here. Most of the  
time, if you are struggling with custom actions, it is because there is  
some other way to represent the relationship than what you had before.  
Just think in terms of “what am I creating here?”

Hope this helps,

Chris Beck  
redmotive
