
Generic Actions in Rails 3 - ivey
http://yehudakatz.com/2009/12/20/generic-actions-in-rails-3/
======
ivey
I absolutely love seeing how Rails 3 is maturing. The fact that it seems to be
truly Merb-flavored probably has something to do with that.

This isn't just "Rails can do what Django does" ... it's why it can, and how
that could be used to do lots of other cool stuff.

~~~
subbu
Its good to see 2 major frameworks learning/borrowing from each other rather
than trying to one-up each other.

------
charliepark
I've been looking around for a while now, with little success ... are there
any timeframe / estimates on when Rails 3 will be live? There's been lots of
hype about it for months, and I'm looking forward to moving over to it, but I
don't know quite how to manage my expectations in terms of projected release
dates. Anybody know?

~~~
donw
No, but this is my question as well. There's plenty of stuff on the net about
how great Rails 3 will be, but the last time I checked out edge Rails (around
three months ago), it felt pretty far from ready for prime time.

They've done a lot of refactoring, and made a ton of improvements, so I can
understand a longer-than-usual development cycle, but all the hype around how
great things will be, without seeing a stable release, is a little unsettling.

------
ubernostrum
While this is neat, the redirect and template-rendering generic views aren't
the ones I'm really interested in. What I'd want if I were looking at Rails is
an equivalent for the content-retrieving generic views (which provide indexes,
archives, date-based navigation, etc.), but I don't see anything about them
here.

~~~
collint
Do you mean the Django admin stuff?

~~~
ubernostrum
No, I mean things like this:

[http://docs.djangoproject.com/en/1.1/ref/generic-
views/#date...](http://docs.djangoproject.com/en/1.1/ref/generic-views/#date-
based-generic-views)

The powerful thing about generic views -- as far as I'm concerned -- is that
they're encapsulated generic logic. Things like "show an individual object" or
"show objects published in December 2009" or whatever, which crop up over and
over in real-world use, and which are best written once and reused over and
over again.

~~~
wycats
I hope I showed that those sorts of things are quite possible using the same
basic techniques that I showed for the redirection and rendering generic
actions. Thanks for the feedback :)

~~~
ubernostrum
Well, it may just be that I don't know enough about Rails, but how _do_ you do
that sort of thing? For example, what's the equivalent data structure to a
QuerySet that you'd pass around as an argument?

~~~
wycats
There are two ways I can think of to achieve a similar effect. Let's use this
example from the Django docs:

    
    
        info_dict = {
          'queryset': Poll.objects.all(),
        }
        (r'^(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', info_dict),
    

One (pretty simple) solution would be to use a block to pull out the object in
question:

    
    
        match "/:id" => object_detail {|params| Poll.find(params[:id]) }
    

Rails 3, with its ActiveRelation integration, could also support a syntax
similar to the QuerySet syntax:

    
    
        match "/:id" => object_detail(Poll.all)
    

where Rails would internally take the Relation from Poll.all and do
@relation.where(:id => params[:id]). To be honest, while the newly available
syntax is nice, lightweight block syntax is pretty nice as well.

