# Some basic questions about REST

**URL:** <https://www.ruby-forum.com/t/some-basic-questions-about-rest/126874>\
**Category:** Rails\
**Created:** [January 23, 2008, 12:58am UTC](https://www.ruby-forum.com/t/some-basic-questions-about-rest/126874 "2008-01-23T00:58:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eggman2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/51bf81/32.png) [@eggman2001](https://www.ruby-forum.com/u/eggman2001)\
**Post date:** [January 23, 2008, 12:58am UTC](https://www.ruby-forum.com/t/some-basic-questions-about-rest/126874/1 "2008-01-23T00:58:21Z")

</div>

I’m trying to get my head around some of the concepts of REST and I’m  
hoping for some clarification.

Lets say I have a site with a resource called ‘books’.

1. I understand that there should be only one controller for the books  
resource, but how would you typically make certain actions available  
only to an authenticated user? Would you add before filters on every  
controller you want to restrict? If so, wouldn’t that be duplication?  
Or is a nice way around the duplication?

2. What if I want to add a resource called ‘authors’ but want to allow  
myself to create authors on the same page that I create books.  
Wouldn’t that be impossible if they’re two separate controllers?

---

<div class="post-metadata">

**Author:** ![eggman2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/51bf81/32.png) [@eggman2001](https://www.ruby-forum.com/u/eggman2001)\
**Post date:** [January 23, 2008, 6:53am UTC](https://www.ruby-forum.com/t/some-basic-questions-about-rest/126874/2 "2008-01-23T06:53:51Z")

</div>

On Jan 23, 4:57 am, eggman2001 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m trying to get my head around some of the concepts of REST and I’m  
> hoping for some clarification.
> 
> Lets say I have a site with a resource called ‘books’.
> 
> 1. I understand that there should be only one controller for the books  
> resource, but how would you typically make certain actions available  
> only to an authenticated user? Would you add before filters on every  
> controller you want to restrict? If so, wouldn’t that be duplication?  
> Or is a nice way around the duplication?  
> Add the before\_filter method at the ApplicationController and do all  
> the authentication their. See  
> if the request is worthy to access a controller and an action or not.  
> That way you would be staying DRY.

> 1. What if I want to add a resource called ‘authors’ but want to allow  
> myself to create authors on the same page that I create books.  
> Wouldn’t that be impossible if they’re two separate controllers?  
> That’s probably simpler also. I think

link\_to :controller =\> :author, :action =\> :create

would do the job.

Anybody to rectify?

---

<div class="post-metadata">

**Author:** ![eggman2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/51bf81/32.png) [@eggman2001](https://www.ruby-forum.com/u/eggman2001)\
**Post date:** [January 23, 2008, 7:20am UTC](https://www.ruby-forum.com/t/some-basic-questions-about-rest/126874/3 "2008-01-23T07:20:15Z")

</div>

To create an author and a book on the same page I would use just the one  
form and use stuff like:

\<%= text\_field “author”, “first\_name” %\>

for the author and

\<%= text\_field “book”, “title” %\>

for the book

which will then be passed in with params[:author] and params[:book]  
respectively.

In your controller you can then:

@author = Author.create!(params[:author])  
@book = @author.books.create!(params[:book])

---

<div class="post-metadata">

**Author:** ![eggman2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/51bf81/32.png) [@eggman2001](https://www.ruby-forum.com/u/eggman2001)\
**Post date:** [January 23, 2008, 12:02pm UTC](https://www.ruby-forum.com/t/some-basic-questions-about-rest/126874/4 "2008-01-23T12:02:58Z")

</div>

You can build a page to alter both authors and books just remember that  
this should be in addition to the architecture but not part of the core.  
According to the ROA as specified in RESTful Web Services all resources  
must be addressable.
