inferring the controller name

0 views
Skip to first unread message

Brian

unread,
Feb 15, 2008, 5:22:42 PM2/15/08
to resources_controller
class ForumsController < ApplicationController
resources_controller_for :forums
end

Rather than requiring :forum to be passed in, a nice default would be
to infer this by the controller's name. Thoughts?

Chris Hapgood

unread,
Feb 15, 2008, 5:28:31 PM2/15/08
to resources_...@googlegroups.com
I agree. And the macro should be resources_controller with an option to
specify the resource. So...

resources_controller :for => :forums


Chris Hapgood
Skype: chris.hapgood
Email: cc...@hapgoods.com


No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.516 / Virus Database: 269.20.5/1279 - Release Date: 14/02/2008
18:35

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.516 / Virus Database: 269.20.5/1279 - Release Date: 14/02/2008
18:35

Ian White

unread,
Feb 15, 2008, 5:28:52 PM2/15/08
to resources_...@googlegroups.com
> Rather than requiring :forum to be passed in, a nice default would be
> to infer this by the controller's name. Thoughts?

Rc used to do this, way back when, but it turned out to be a bit too
magical in practice. Also, there are quite a few cases where you have
many controllers for one resource type (some nesting examples,
namespaced (eg admin) controllers, things like that)

Cheers,
Ian

--
Argument from Design--We build web applications
Western House 239 Western Road Sheffield S10 1LE UK
Mobile: +44 (0)797 4678409 | Office: +44 (0)114 2667712
<http://www.ardes.com/> | <http://blog.ardes.com/ian>

Ian White

unread,
Feb 15, 2008, 5:29:58 PM2/15/08
to resources_...@googlegroups.com
> resources_controller :for => :forums
Interesting, What would the benefit of this be?

Chris Hapgood

unread,
Feb 15, 2008, 5:32:21 PM2/15/08
to resources_...@googlegroups.com
"Also, there are quite a few cases where you have many controllers for one
resource type"

True, Ian. But now that RC supports multiple enclosing resource types
automatically for a given controller, I've been able to nuke many, many
degenerate controllers. Maybe it's an appropriate time to reconsider
default resource names.

My 2p.

-Chris


Chris Hapgood
Phone: +1 434 989 8584
Skype: chris.hapgood
Email: cc...@hapgoods.com

Cheers,
Ian

No virus found in this incoming message.

Brian

unread,
Feb 15, 2008, 5:34:14 PM2/15/08
to resources_controller
I like Chris' idea of having resources_controller with :for as an
option. This way you aren't repeating yourself in cases where it's
not needed.

Chris Hapgood

unread,
Feb 15, 2008, 5:34:39 PM2/15/08
to resources_...@googlegroups.com
The benefit is that when you use the default determination of resources (if
that should come to pass), it reads more nicely. To wit:

1. resources_controller_for

2. resources_controller

My teachers always told me to never end a sentence with a preposition!

-Chris


Chris Hapgood
Skype: chris.hapgood
Email: cc...@hapgoods.com

-----Original Message-----
From: resources_...@googlegroups.com
[mailto:resources_...@googlegroups.com] On Behalf Of Ian White
Sent: Friday, February 15, 2008 17:30
To: resources_...@googlegroups.com
Subject: Re: inferring the controller name

No virus found in this incoming message.

Ian White

unread,
Feb 15, 2008, 5:38:05 PM2/15/08
to resources_...@googlegroups.com
> 1. resources_controller_for

> My teachers always told me to never end a sentence with a preposition!

But 1, just like 'has_many' is the start of a sentence :)

So you're proposing syntactic sugar change, I thought maybe you were
thinking of something else

Chris Hapgood

unread,
Feb 15, 2008, 6:08:45 PM2/15/08
to resources_...@googlegroups.com
Yes, it's mostly a syntactic sugar change, but it also addresses the
crushing need for an option hash key to specify the resource name!


Chris Hapgood
Phone: +1 434 989 8584

Skype: chris.hapgood
Email: cc...@hapgoods.com

-----Original Message-----
From: resources_...@googlegroups.com
[mailto:resources_...@googlegroups.com] On Behalf Of Ian White
Sent: Friday, February 15, 2008 17:38
To: resources_...@googlegroups.com
Subject: Re: inferring the controller name


> 1. resources_controller_for

No virus found in this incoming message.

Reply all
Reply to author
Forward
0 new messages