How to know if enclosing resource is singleton or not?

1 view
Skip to first unread message

valdas

unread,
Feb 17, 2009, 8:01:12 AM2/17/09
to resources_controller
How to know if enclosing resource is singleton or not?

Ian White

unread,
Feb 19, 2009, 4:39:22 PM2/19/09
to resources_controller
Hi Valdas,

On Feb 17, 1:01 pm, valdas <griausti...@gmail.com> wrote:
> How to know if enclosing resource is singleton or not?

I'm unsure what you mean. Do you mean something like, can you reflect
on the current enclosing resources, and find whether they are
singleton or collection? If you do mean this, then I think the answer
is no, but I;ve never had a reason to implement such a facility. If
you have such a reason, could you say more?

Cheers,
Ian


valdas

unread,
Feb 25, 2009, 6:08:11 PM2/25/09
to resources_controller
Hello again,

Yes indeed: given current resource reflect enclosing resource and tell
if it singleton or not. Need arose when I was programing admin
interfaces and in the view I want to give link back not only to
specific enclosing resource but also to list of enclosing resources
that is enclosing resource controller 'index' action. But current
resource can be enclosed either by singleton or normal resource. If I
use 'enclosing_resources_path' helper it gives an error when enclosing
resource is singleton - given method does not exist.

When I wrote this explanation some thoughts came out:

We need some way to know which controller is responsible for that
resource and then check respond_to?(:index), or even user
resource_controller specification. But this relationship could be
easily obtained for standard cases: User model - UserControler, but
what about custom naming or other cases?

Any other thoughts?

Valdas

Ian White

unread,
Feb 26, 2009, 5:13:54 AM2/26/09
to resources_...@googlegroups.com
In advance of better reflection for RC, one quick way to check whether
an enclosing resource is singleton could be to use the
fact that enclosing_resources_path won't be defined. i.e.

(in your controller, or App controller...)

protected
def enclosing_resource_singleton?
(enclosing_resources_path rescue nil) ? true : false
end
helper_method :enclosing_resource_singleton?

(or something like this, I just came up with this off the top of my
head)

Cheers,
Ian
Reply all
Reply to author
Forward
0 new messages