Forum: Ruby on Rails RESTful url's

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
06944d16c08b78c0a2fadb6dd709951d?d=identicon&s=25 Jeremy W. (nuby2ruby)
on 2007-02-15 01:55
I am having some trouble in trying to figure out how to add a date and
time to my URL and leave out the :id.

I have

map.resources :events do |events|
  events.resources :showtimes
end

the url I want to be shown is /events/1/showtimes/2007-2-14/18/00

but what I am getting is /events/1/showtimes/1

I know I can do a :path_prefix and have the date and time put in before
showtimes, but that's not what I want.

Any help would be great.

ALSO, a buddy of mine thinks that REST conflicts with Object thinking, I
just wanted to get everyone else's opinion on that.

Thanks
Df10091131ec3e0b93a831c9a18cdc36?d=identicon&s=25 Alex W. (squeegy)
on 2007-02-15 02:06
Jeremy Woertink wrote:
> I am having some trouble in trying to figure out how to add a date and
> time to my URL and leave out the :id.
>
> I have
>
> map.resources :events do |events|
>   events.resources :showtimes
> end
>
> the url I want to be shown is /events/1/showtimes/2007-2-14/18/00
>
> but what I am getting is /events/1/showtimes/1

You may not be able to use restful routes with this.  Simply because
that route is not restful.  REST says every resource has a single ID,
yet that route has 3 bits of data to identify a showtime: date, hour and
minute.

you might be able to do a route like:

  /events/1/showtimes/2007-2-14-18-00/

by doing something like

  class Showtime < ActiveRecord::Base
    def to_param
      time.strftime('someformattingstringhere')
    end
  end

But you will have to fetch all your stuff via

  Showtime.find_by_time(params[:id])

Since you id is now a time stamp, instead of a primary key.

> ALSO, a buddy of mine thinks that REST conflicts with Object thinking, I
> just wanted to get everyone else's opinion on that.

Object thinking?  Is that a cult?

If anything, it makes the web more object oriented by identifying a
specific url with a specific object or resource.  HTTP verbs are like
the methods on that object.  Makes more OO sense to me than a bunch of
controllers that you can't really tell what data they manipulate without
looking at the source code.
7fe43c7e891c77a9e64a9dea3b028fda?d=identicon&s=25 Daniel W. (rabbitcreative)
on 2007-02-15 02:45
Alex Wayne wrote:
> Object thinking?  Is that a cult?
>
> If anything, it makes the web more object oriented by identifying a
> specific url with a specific object or resource.  HTTP verbs are like
> the methods on that object.  Makes more OO sense to me than a bunch of
> controllers that you can't really tell what data they manipulate without
> looking at the source code.

I'm that buddy.

No, object thinking is not a cult. I prefer that phrase because it is
less bogged down by the abuse of the term object-oriented.

"OOP to me means only messaging, local retention and protection and
hiding of state-process, and extreme late-binding of all things." - Alan
Kay, father of OOP

I think REST violates OT in a very subtle fashion. Objects have
responsibilities _as defined by the problem-space_. Decomposition of the
domain, its problems and its objects helps to create objects that are
light and well-defined. There are no limits on what an object can do
save what the problem domain defines.

REST seeks to minimize the number of responsibilities an object can
assume, while increasing the number of objects in the problem domain,
sometimes absurdly so.

REST places no limits on the kinds of objects that can be created, and
too many choices can lead to crappy choices being made.

> Makes more OO sense to me than a bunch of
> controllers that you can't really tell what data
> they manipulate without looking at the source code.

This can also be true of a REST-oriented web site. Just because you're
using REST techniques doesn't mean your implementation makes sense, or
is really REST-like. Likewise with what so many people consider to be
object-oriented code.
peter royal (Guest)
on 2007-02-15 03:42
(Received via mailing list)
On Feb 14, 2007, at 5:06 PM, Alex Wayne wrote:
>> the url I want to be shown is /events/1/showtimes/2007-2-14/18/00
>>
>> but what I am getting is /events/1/showtimes/1
>
> You may not be able to use restful routes with this.  Simply because
> that route is not restful.  REST says every resource has a single ID,
> yet that route has 3 bits of data to identify a showtime: date,
> hour and
> minute.

I thought REST just says a resource has a single *URL*. Its Rails
that's imposing the single-ID requirement.

To the original poster, you can definitely do RESTful URL's, you just
have to do more work, and can't use the handy map.resources, since
that's imposing the single-ID req.

-pete
This topic is locked and can not be replied to.