views:

464

answers:

1

I need to use one of the resourceful controllers plugins - resources_controller/ resource_controller/make_resourceful as I have several polymorphic models and the models have to be either initialized/build depending on the route.

For example:

www.example.com/groups/1/pages
www.example.com/projects/1/pages

where page acts as polymorphic object as both Group and Project have many pages. So I am thinking of using one of the aforementioned plugins to make pages_controller adapt to both routes. All three plugins works fine and differences are just their implementation of recognizing the routes and loading the models based on that.

Now I want to add sub-domain support using Subdomain_fu plugin so the above example would be:

Site1.example.com/groups/1/pages
Site1.example.com/projects/1/pages

Site2.example.com/groups/2/pages
Site2.example.com/projects/2/pages

On looking at all the three plugins, I don't see any way for them to start loading the resources from my subdomain object, as the subdomain is not part of the route. Any advise on what I am trying to accomplish in a dry/restful way?

A: 

I don't know how to do that with resources_controller but i was able to pull off the same thing with the inherited_resources plugin.

Here is how i accomplished it:

In my application controller I set up a before_filter to find the subdomain:

def set_subdomain @subdomain = Subdomain.find_by_url( request.host ) end

Then in my controllers Using inherited resources I set the @subdomain association using the very cool method "begin_of_association_chain"

protected

def begin_of_association_chain

@subdomain

end

Agile web development has great documentation.

Aaron Renoir
@Aaron - Quite interestingly, I am studying the inherited_resources plugin and doing the same thing as you have suggested before even finding your response. But I got another problem with inherited_resources. I have links like site1.example.com/photos, site1.example.com/events/x/photos, site1.example.com/groups/x/photos, site1.example.com/groups/x/events/x/photos, and so on, but inherited_resources is failing. I tried different combination of using belongs_to, nested_belongs_to, polymorphic_belongs_to, but no matter what I couldn't get the end result that I am expecting. any feedback?
satynos