Parent controller without a parent controller?

0 views
Skip to first unread message

Randy

unread,
Mar 5, 2009, 1:10:33 AM3/5/09
to resource_controller
Hi,

I'd like my /topics/ url to serve topics for the current user.
Primarily, it means:

* Fetch the collection/object relative to that current user
* Ensure that on create and update, the user hasn't tried to stuff the
topic into some other user's list

I was doing those with:

before_filter :fetch_topic, :except => [ :new, :create ]
before_filter :check_userid, :only => [ :create, :update ]

I'm now trying to switch to resource_controller, and I've defined
these methods to provide the parent object - so far, so good. The
fetch_topic() method is providing @user, btw, from
restful_authentication's current_user().

def parent_type
:user
end
def parent_object
@user
end

I'm suspecting that I need less of the before_filter stuff, but I'm
not sure how I cover the desired behavior without it - any help?

It's not clear to me that I've done everything I need to by defining
the two methods above. I would welcome any corrections on that or on
general stylistic recommendations.

Thanks,

Randy

James Golick

unread,
Mar 7, 2009, 3:22:39 PM3/7/09
to resource_...@googlegroups.com
Hi Randy,

parent_type gets computed automatically by r_c, so you don't want to override that except in very specific cases.

You don't need any of those filters - r_c will handle that all for you.

-J.

Randy

unread,
Mar 8, 2009, 5:00:53 PM3/8/09
to resource_controller

On Mar 7, 1:22 pm, James Golick <jamesgol...@gmail.com> wrote:
> You don't need any of those filters - r_c will handle that all for you.

My specs indicate that they aren't being handled. I must be doing
something wrong? Can you tell what?

http://gist.github.com/75896

Randy

Peter Jaros

unread,
Mar 31, 2009, 2:33:14 PM3/31/09
to resource_controller
On Mar 7, 4:22 pm, James Golick <jamesgol...@gmail.com> wrote:
> Hi Randy,
> parent_type gets computed automatically by r_c, so you don't want to
> override that except in very specific cases.

Actually, I needed to do the same thing. parent_type seems to only
exist if the route is nested, and parent_object is only used if
parent_type exists. My case is just like Randy's: the collection is
implicitly scoped to the current user, not scoped to a parent in the
route.

Peter

James Golick

unread,
Mar 31, 2009, 2:43:09 PM3/31/09
to resource_...@googlegroups.com
Just override end_of_association_chain to return the relevant association proxy, then.

Peter Jaros

unread,
Mar 31, 2009, 6:59:19 PM3/31/09
to resource_...@googlegroups.com
On Tue, Mar 31, 2009 at 2:43 PM, James Golick <james...@gmail.com> wrote:
> Just override end_of_association_chain to return the relevant association
> proxy, then.

Ah, that works.

James, thanks for an awesome plugin. My controllers are a joy to write now.

Is there clear documentation somewhere of the API? Most of what I
understand is either in an example in the Readme or I've inferred from
there. The RDoc has lots of methods listed, but it's not clear which
are there to be overridden and which are purely internal. I had no
idea that end_of_association_chain was something I should be using.

Luckily the source is usually clear enough to read. :)

Peter

James Golick

unread,
Apr 2, 2009, 9:33:27 AM4/2/09
to resource_...@googlegroups.com
I thought there was an example in the README, but maybe not. As always, patches happily accepted :D
Reply all
Reply to author
Forward
0 new messages