# RESTful photo album

**URL:** <https://www.ruby-forum.com/t/restful-photo-album/184848>\
**Category:** Rails\
**Created:** [March 9, 2010, 2:01pm UTC](https://www.ruby-forum.com/t/restful-photo-album/184848 "2010-03-09T14:01:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![DmitryPush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/46a35a/32.png) [@DmitryPush](https://www.ruby-forum.com/u/DmitryPush)\
**Post date:** [March 9, 2010, 2:01pm UTC](https://www.ruby-forum.com/t/restful-photo-album/184848/1 "2010-03-09T14:01:10Z")

</div>

Hi, all!  
I’m new in Rails.  
I’ve read “Agile web development” and now I want made my very first  
rails application - photo album.  
But I don’t know how to design it RESTful.

For example I have 3 chapters and 100 photos on each one and i want  
list only 10 photos on page.  
How should look request for such resource?  
Maybe:  
site.my/chapter/2/4  
(controller:chapter, action: chapter\_id=2, page=4)  
If its good then how to send to controller 2 parameters ?

Or maybe you can explain me how it can be done right way?

And now I also want know in general how to process request like  
site.my/say/hello/to/homer  
I know if it just site.my/say/hello - then ‘say’ - it’s controller  
and’ hello’ - it’s action, but what when ‘to’ and ‘homer’?  
How exactly tell my rails application whet I want say hello to Homer?

Thanks in advance!  
PS sorry for so many stupid questions but I don’t have any one next to  
me who about Rails((

---

<div class="post-metadata">

**Author:** ![DmitryPush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/46a35a/32.png) [@DmitryPush](https://www.ruby-forum.com/u/DmitryPush)\
**Post date:** [March 9, 2010, 6:22pm UTC](https://www.ruby-forum.com/t/restful-photo-album/184848/2 "2010-03-09T18:22:43Z")

</div>

DmitryPush wrote:

> Hi, all!  
> I’m new in Rails.  
> I’ve read “Agile web development” and now I want made my very first  
> rails application - photo album.  
> But I don’t know how to design it RESTful.
> 
> For example I have 3 chapters and 100 photos on each one and i want  
> list only 10 photos on page.

Forget about trying to engineer your URLs (save that for later if you  
want).  
Take a look at mislav-will\_paginate for showing N items per page. Mix  
that with good use of the in\_groups\_of, and you can have a nice layout  
in rows and columns if that’s your desire.

> And now I also want know in general how to process request like  
> site.my/say/hello/to/homer  
> I know if it just site.my/say/hello - then ‘say’ - it’s controller  
> and’ hello’ - it’s action, but what when ‘to’ and ‘homer’?  
> How exactly tell my rails application whet I want say hello to Homer?

You’ll want to read up on specifying routes in rails to accomplish that  
task.

---

<div class="post-metadata">

**Author:** ![DmitryPush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/46a35a/32.png) [@DmitryPush](https://www.ruby-forum.com/u/DmitryPush)\
**Post date:** [March 9, 2010, 10:59pm UTC](https://www.ruby-forum.com/t/restful-photo-album/184848/3 "2010-03-09T22:59:49Z")

</div>

DmitryPush wrote:

> site.my/chapter/2/4

It is my opinion that people often go overboard with the REST concepts.

As far as I’m concerned there’s nothing non-RESTful about:

[http://host/chapter/2/photos?page=4&per\_page=10](http://host/chapter/2/photos?page=4&per_page=10)

The URL still identifies the resource, which would be the collection of  
photos (nested under the chapter identified by 2). The query string is  
just for controlling the paging. I don’t see this as part of the  
resource identifier URL, so the query string is a good place for it to  
live.

---

<div class="post-metadata">

**Author:** ![DmitryPush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/46a35a/32.png) [@DmitryPush](https://www.ruby-forum.com/u/DmitryPush)\
**Post date:** [March 9, 2010, 11:08pm UTC](https://www.ruby-forum.com/t/restful-photo-album/184848/4 "2010-03-09T23:08:29Z")

</div>

On Tue, Mar 9, 2010 at 3:59 PM, Robert W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> As far as I’m concerned there’s nothing non-RESTful about:
> 
> [http://host/chapter/2/photos?page=4&per\_page=10](http://host/chapter/2/photos?page=4&per_page=10)

I agree, but all the question marks and ampersands pretty much  
guarantee Google won’t index it.

–  
Greg D.  
[destiney.com](http://destiney.com) | [gregdonald.com](http://gregdonald.com)

---

<div class="post-metadata">

**Author:** ![DmitryPush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/46a35a/32.png) [@DmitryPush](https://www.ruby-forum.com/u/DmitryPush)\
**Post date:** [March 9, 2010, 11:32pm UTC](https://www.ruby-forum.com/t/restful-photo-album/184848/5 "2010-03-09T23:32:48Z")

</div>

Greg D. wrote:

> On Tue, Mar 9, 2010 at 3:59 PM, Robert W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > As far as I’m concerned there’s nothing non-RESTful about:
> > 
> > [http://host/chapter/2/photos?page=4&per\_page=10](http://host/chapter/2/photos?page=4&per_page=10)
> 
> I agree, but all the question marks and ampersands pretty much  
> guarantee Google won’t index it.

I certainly get that point. However, that’s a different issue, unrelated  
to the RESTfulness of a URI.

There are cases where it’s probably a good thing that Google doesn’t  
index certain pages. There’s way to much garbage that people force  
Google to index that just makes finding what you really want next to  
impossible.

Forums that get indexed come to mind. It drives me nuts that such a  
large percentage of what I’m looking for gets obscured by a bunch of  
useless hits on forum discussions. Blogs, yes. Forum posts I could live  
without in my search results!

SEO is great, and useful, for sites that provide really useful search  
content, but there much that needs to be put on the web that really has  
no business showing up in Google results.

---

<div class="post-metadata">

**Author:** ![DmitryPush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/46a35a/32.png) [@DmitryPush](https://www.ruby-forum.com/u/DmitryPush)\
**Post date:** [March 10, 2010, 7:38am UTC](https://www.ruby-forum.com/t/restful-photo-album/184848/6 "2010-03-10T07:38:48Z")

</div>

Thx!  
Sounds good.  
I’ll try it and later I’ll post hear where it drive me to:)

---

<div class="post-metadata">

**Author:** ![DmitryPush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/46a35a/32.png) [@DmitryPush](https://www.ruby-forum.com/u/DmitryPush)\
**Post date:** [March 10, 2010, 7:56am UTC](https://www.ruby-forum.com/t/restful-photo-album/184848/7 "2010-03-10T07:56:58Z")

</div>

Hi,

you can try from other perspective, if you already have the  
functionality to paginate the records in your model or controller and  
the only need that you have are the parameters, you can try with a  
simple map.connect like this =\>

map.connect “:controller/:id\_chapter/:page”

and ActionController will map =\>

i rann it in the rails console =\>

> > rs.recognize\_path “chapter/2/4”

{:action =\> ‘index’, :page =\> “2”, :id\_chapter =\> “4”,  
:controller=\>“chapter”)

this variables are aviable in your @params.

but you’ll be better if take the paginate-plugin approach, donÂ´t put  
that kind of logic in your route sistem.

Pdta: Sorry by mi English

Cristian Vasquez  
MedellÃ­n-Colombia
