Concerns about starting a new "RESTfull compliant" site

0 views
Skip to first unread message

diegal

unread,
Feb 21, 2007, 11:20:47 AM2/21/07
to Ruby on Rails: Talk
Hi all.

I'm just starting a new app from scratch, and want to do it
RESTfully...

I've seen many blog posts, articles, and DHH's RailsConf keynote about
REST and resources and still have some questions about it.

I've no problems mapping some concepts to resources like the classics
article, post, person, event, etc... But some aspects of a WebApp I
find no REST answer, like a "homepage" which shows a summary of the
latests articles, posts and events in the site. It's not about 1
resource or a collection of resources of the same kind, it's about a
bunch of different resources.

Which would be the best RESTful approach to this kind of
functionality?

I obviously missed some point here or haven't realized it yet.

Other examples I can think of: a dashboard, "about this site" pages,
etc...

A related question is how to manage "layout" related data. I mean, if
I have a sidebar in my layout which needs some data to be retrieved in
every request, I'd usually use a before_filter at the
ApplicationController level. Is that kind of controller activity
(doing things beyond the scope of the specific managed resource) still
considered "clean" thinking in pure RESTfullness compliance?

Thank you,
Diego

Ball, Donald A Jr (Library)

unread,
Feb 21, 2007, 12:10:05 PM2/21/07
to rubyonra...@googlegroups.com
> I've no problems mapping some concepts to resources like the
> classics article, post, person, event, etc... But some
> aspects of a WebApp I find no REST answer, like a "homepage"
> which shows a summary of the latests articles, posts and
> events in the site. It's not about 1 resource or a collection
> of resources of the same kind, it's about a bunch of
> different resources.

In this case, your homepage is a resource which summarizes the latest
changes to the articles, posts, and events resources. In this case, GET
is a meaningful request, while POST, PUT, and DELETE are probably not.
Your dashboard resource probably acts similarly, while your "about this
site" resource probably behaves more like a traditional static file.

- donald

diegal

unread,
Feb 21, 2007, 12:23:06 PM2/21/07
to Ruby on Rails: Talk
On 21 feb, 15:10, "Ball, Donald A Jr \(Library\)"

Mmm... Ok. But I see no Homepage model (or dashboard, or about) in
that.
Would it be teorically ok (thinking of REST and resources) to have a
HomepageController which manages no model?

All examples I've seen have a 1 to 1 relation between a Controller and
a Model.

Diego

Russell Norris

unread,
Feb 21, 2007, 1:48:34 PM2/21/07
to rubyonra...@googlegroups.com
For my app, I discovered that my dashboard seemed to fit nicely as the index method of my sessions controller. You log in [new/create] and out [delete], change options about what you want to view [edit/update] and read a summary of sorts about what's going on this session [index]. This might not work in your case but hopefully it's a good example of how to look at things from a different angle.

RSL

diegal

unread,
Feb 21, 2007, 2:17:00 PM2/21/07
to Ruby on Rails: Talk
That seems ok. But maybe it seems a bit special for that particular
case.

One more related concern is how to support different "views" of the
same resource. I mean, how could I have an "administrative" interface
where I can CRUD resources. For example, the path "/articles" would
show the list of articles with it's summaries so a site visitor can
read them. But if I'm in the administrative interface "/articles"
should render completely different showing just the titles and the
classic edit & destroy links per article.
Should I configure a new "aspect" route/action caled "admin" or
something?
map.resources :articles, :collection => {:admin => :get}
# /articles;admin

ArticlesController < ActiveController
def admin
@articles = ...
end
end

It just doesn't feel good...

Thanks for the help.
Diego

On 21 feb, 16:48, "Russell Norris" <sco...@gmail.com> wrote:
> For my app, I discovered that my dashboard seemed to fit nicely as the index
> method of my sessions controller. You log in [new/create] and out [delete],
> change options about what you want to view [edit/update] and read a summary
> of sorts about what's going on this session [index]. This might not work in
> your case but hopefully it's a good example of how to look at things from a
> different angle.
>
> RSL
>

Paul Barry

unread,
Feb 21, 2007, 11:01:03 PM2/21/07
to Ruby on Rails: Talk
Good question, I've been wondering the same thing myself. My current
solution is to have an ArticlesController and an
Admin::ArticlesController, but that doesn't feel right either.

Pat Maddox

unread,
Feb 21, 2007, 11:28:34 PM2/21/07
to rubyonra...@googlegroups.com
On 2/21/07, diegal <diego....@gmail.com> wrote:
>
> Hi all.
>
> I'm just starting a new app from scratch, and want to do it
> RESTfully...
>
> I've seen many blog posts, articles, and DHH's RailsConf keynote about
> REST and resources and still have some questions about it.
>
> I've no problems mapping some concepts to resources like the classics
> article, post, person, event, etc... But some aspects of a WebApp I
> find no REST answer, like a "homepage" which shows a summary of the
> latests articles, posts and events in the site. It's not about 1
> resource or a collection of resources of the same kind, it's about a
> bunch of different resources.

In your homepage example, what's the resource that you're exposing to people?

...

I can't think of one either. It's really just a landing zone with
links to interesting resources. I guess maybe you could use a map
metaphor, in which case you'd have a MapsController.

It's overkill though. Bottom line is that this sort of thing doesn't
fit the resource paradigm. So don't try to shoehorn it.

For stuff like the homepage or an "about us" page, I just create a
MainController. The default route (':controller/:action/:id') works
fine. You end up with stuff like /main/about_us, /main/privacy, etc.

REST is cool and all, but for some things it doesn't provide any value
to expose them as resources, and it can just be plain awkward.

> A related question is how to manage "layout" related data. I mean, if
> I have a sidebar in my layout which needs some data to be retrieved in
> every request, I'd usually use a before_filter at the
> ApplicationController level. Is that kind of controller activity
> (doing things beyond the scope of the specific managed resource) still
> considered "clean" thinking in pure RESTfullness compliance?

Of course.

The "meat" of your code is going to be finding/modifying the resource.
I put that in quotes because for the most part it's going to be very
simple, basic code. But the idea is that you're just giving the user
a representation of some resource. If you want to make the
surrounding layout pretty, or provide useful information or links, go
for it.

Pat

diegal

unread,
Feb 23, 2007, 2:52:06 AM2/23/07
to Ruby on Rails: Talk
I've been researching about REST and all... and since I feel many
people has the same questions, I decided to sum them up in another
thread.

I suggest we move this conversation to that thread instead:

http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/7448542a9ea0a567

Diego

On 22 feb, 02:28, "Pat Maddox" <perg...@gmail.com> wrote:

Reply all
Reply to author
Forward
Message has been deleted
0 new messages