On Thu, Jul 8, 2010 at 8:50 AM, Spiralis <[email protected]> wrote:
> Hi all,
>
> I am working on a project where I have a customer and a project model/
> controller setup hobo-style.
>
> The relations are so that a company has many projects, and a project
> belongs to a company.
>
> This means that I get the routes /companies and /projects 'for free'.
>
> However, I want to access projects via the url like this:
>
> * List of projects for a given company:
>    /companies/1-ACME/projects
> * Project details for a given company:
>    /companies/1-ACME/projects/1-Mickey Mouse - SteamBoat Willie 2
>
> Hobo already have auto_actions_for, but it seems to be limited to :new
> and :create.
>

auto_actions_for also supports :index, which will handle the first case above.

For the second, the company ID isn't *technically* required to
complete the action - the project ID is globally unique (unless you've
done some sort of Really Bad Thing to the DB...). It's probably better
from an implementation standpoint to just link directly:

/projects/1-etc

The SEO fanatics may disagree, but it works...

If you actually want URLs like the above, just add them to the routes
file *below* the Hobo add_routes call (else you'll get weird "can't
find Product with ID 'new' errors):

map.product_for_company '/companies/:company_id/products/:id',
:controller => 'products', 'action' => 'show'

But you'll have a heck of a time getting even vanilla Rails helpers to
use it consistently - for instance, this won't work right:

<%= link_to @product.name, @product %>

That'll give you the standard REST-style /products/:id path - I think
you'd need something like:

<%= link_to @product.name, [[email protected], @product] %>

(assuming that link_to / url_for supports the same magic as form_for)

The additional hassles involved in prodding the <a> tag to do this are
left to the reader. :)

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.

Reply via email to