# Creating records in two models in a RESTful way

**URL:** <https://www.ruby-forum.com/t/creating-records-in-two-models-in-a-restful-way/99769>\
**Category:** Rails\
**Created:** [July 25, 2006, 12:42pm UTC](https://www.ruby-forum.com/t/creating-records-in-two-models-in-a-restful-way/99769 "2006-07-25T12:42:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rwl4](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@rwl4](https://www.ruby-forum.com/u/rwl4)\
**Post date:** [July 25, 2006, 12:42pm UTC](https://www.ruby-forum.com/t/creating-records-in-two-models-in-a-restful-way/99769/1 "2006-07-25T12:42:47Z")

</div>

Hey everyone,

I have a philosophical question here. Say I have a website that uses two  
models for accounts: Person and Company. Normally I would just have  
/accounts/new for user signup.

However, the RESTful way to do it is to have /people and /companies.  
Unfortunately, this doesn’t account for a situation where you’d have a  
one-page signup form. I wouldn’t want this to be a two page process,  
because somebody could close their browser mid-process and that would  
leave me with an incomplete account with only a Company or Person entry.  
How would you all solve this in a RESTful way?

I am strongly considering adopting REST for most of my projects, but I  
can’t decide how I want to solve this.

Regards,

Ray

---

<div class="post-metadata">

**Author:** ![rwl4](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@rwl4](https://www.ruby-forum.com/u/rwl4)\
**Post date:** [July 25, 2006, 1:50pm UTC](https://www.ruby-forum.com/t/creating-records-in-two-models-in-a-restful-way/99769/2 "2006-07-25T13:50:31Z")

</div>

You need to provide data model for clearing your question.

Why not /account ?

On 7/25/06, Raymond L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> leave me with an incomplete account with only a Company or Person entry.  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
rm -rf / 2\>/dev/null - [http://null.in](http://null.in)

“Things do not happen. Things are made to happen.” - JFK

---

<div class="post-metadata">

**Author:** ![rwl4](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@rwl4](https://www.ruby-forum.com/u/rwl4)\
**Post date:** [July 25, 2006, 2:29pm UTC](https://www.ruby-forum.com/t/creating-records-in-two-models-in-a-restful-way/99769/3 "2006-07-25T14:29:27Z")

</div>

> I have a philosophical question here. Say I have a website that uses two  
> models for accounts: Person and Company. Normally I would just have  
> /accounts/new for user signup.

I asked DHH this same question on his blog comments -  
[http://www.loudthinking.com/arc/000593.html](http://www.loudthinking.com/arc/000593.html) - and he said that an  
additional controller, e.g. signup, with a create action was his own  
solution.

To see his answer, search for “signup” on that page.

Cheers  
Nic

---

<div class="post-metadata">

**Author:** ![rwl4](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@rwl4](https://www.ruby-forum.com/u/rwl4)\
**Post date:** [July 25, 2006, 2:39pm UTC](https://www.ruby-forum.com/t/creating-records-in-two-models-in-a-restful-way/99769/4 "2006-07-25T14:39:19Z")

</div>

I’m just wondering.  
Are you planning to provide external software to create accounts? Why  
are you doing this using REST? It just seems to me like you are making  
things more complex and unnatural just because DHH says it’s the way.  
Love the guy but I don’t see why adopting REST for everything in every  
project can actually lead to better looking code.

On 7/25/06, Raymond L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> leave me with an incomplete account with only a Company or Person entry.  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–

---

<div class="post-metadata">

**Author:** ![rwl4](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@rwl4](https://www.ruby-forum.com/u/rwl4)\
**Post date:** [July 25, 2006, 2:43pm UTC](https://www.ruby-forum.com/t/creating-records-in-two-models-in-a-restful-way/99769/5 "2006-07-25T14:43:53Z")

</div>

> Normally I would just have  
> /accounts/new for user signup.

Thats exactly what rest wants you to do. Accessing ideas or concepts  
with limited verbs is what is important. If you come up with a concept  
that encapsulates a million different tables in your database it would  
still be just fine to expose that in a url (have a controller for that  
idea). The only thing you really need to watch out for is crazy verbs.  
Not crazy abstract ideas, they’re fine (even encouraged!). As long as  
you don’t stray from the regular list, show, edit, new, etc. actions in  
your controllers you are probably doing a good job keeping things  
restful.

Thats at least my take.

Raymond L. wrote:

> Hey everyone,
> 
> I have a philosophical question here. Say I have a website that uses two  
> models for accounts: Person and Company. Normally I would just have  
> /accounts/new for user signup.
> 
> However, the RESTful way to do it is to have /people and /companies.  
> Unfortunately, this doesn’t account for a situation where you’d have a  
> one-page signup form. I wouldn’t want this to be a two page process,  
> because somebody could close their browser mid-process and that would  
> leave me with an incomplete account with only a Company or Person entry.  
> How would you all solve this in a RESTful way?
> 
> I am strongly considering adopting REST for most of my projects, but I  
> can’t decide how I want to solve this.
> 
> Regards,
> 
> Ray

---

<div class="post-metadata">

**Author:** ![rwl4](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@rwl4](https://www.ruby-forum.com/u/rwl4)\
**Post date:** [July 25, 2006, 2:49pm UTC](https://www.ruby-forum.com/t/creating-records-in-two-models-in-a-restful-way/99769/6 "2006-07-25T14:49:26Z")

</div>

> I’m just wondering.  
> Are you planning to provide external software to create accounts? Why  
> are you doing this using REST? It just seems to me like you are making  
> things more complex and unnatural just because DHH says it’s the way.  
> Love the guy but I don’t see why adopting REST for everything in every  
> project can actually lead to better looking code.

Considering that less code is better looking code, I’d say REST leads to  
better  
looking code 🙂

## Regards, Rimantas

[http://rimantas.com/](http://rimantas.com/)

---

<div class="post-metadata">

**Author:** ![rwl4](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@rwl4](https://www.ruby-forum.com/u/rwl4)\
**Post date:** [July 25, 2006, 3:51pm UTC](https://www.ruby-forum.com/t/creating-records-in-two-models-in-a-restful-way/99769/7 "2006-07-25T15:51:11Z")

</div>

On 2006-07-25 08:45:26 -0400, “Rimantas L.”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) said:

> Regards,  
> Rimantas

I agree that the signup controller will end up using less code. I am  
curious how list resorting fits into this?

I usually have a sort method in my controller that handles it, but  
should I somehow integrate that into my update method?

## I don’t think a sort verb is too bad, but I can see how there could end up being a lot of different variable because of javascript interaction.

://  
Nathan H.

---

<div class="post-metadata">

**Author:** ![rwl4](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@rwl4](https://www.ruby-forum.com/u/rwl4)\
**Post date:** [July 25, 2006, 4:16pm UTC](https://www.ruby-forum.com/t/creating-records-in-two-models-in-a-restful-way/99769/8 "2006-07-25T16:16:59Z")

</div>

> I usually have a sort method in my controller that handles it, but  
> should I somehow integrate that into my update method?

That’s one aspect of DHH’s CRUD superplan that I haven’t seen happy  
solutions to:

/accounts/14 - returns one Account  
/accounts - returns all Account

- how do you get a subset (search criteria, pagination etc)
- how do you order

Obviously the answer is to add more parameters  
(accounts?sort=name&sort\_dir=asc&page=2) but then what have we achieved  
really?

---

<div class="post-metadata">

**Author:** ![rwl4](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@rwl4](https://www.ruby-forum.com/u/rwl4)\
**Post date:** [July 25, 2006, 5:15pm UTC](https://www.ruby-forum.com/t/creating-records-in-two-models-in-a-restful-way/99769/9 "2006-07-25T17:15:04Z")

</div>

It would be great if someone could inform DHH of this thread!
