Thanks a bunch for the advise and code, works like a charm.

On Mar 27, 12:41 pm, Stephen Eley <[email protected]> wrote:
> On Fri, Mar 27, 2009 at 2:52 PM, Kennard Smith <[email protected]> wrote:
>
> > Thanks for the reply
> > unfortunately the default routes don't work with resources
>
> You're right, you can't do it with the nice little resource helpers.
> But you can do it yourself with matching.  I had this same issue with
> a CMS proto-slice I was working on.  Here's how I solved it, pretty
> much:
>
> Merb::Router.prepare do
>   identify(Content => :id) do
>     match("/(:id)").to(:controller => "contents") do
>       match("(/)contents").to(:action => "index").name(:contents)
>       match("/edit").to(:action => "edit").name(:edit_content)
>       match("(/)new").to(:action => "new").name(:new_content)
>       match("/delete").to(:action => "delete").name(:delete_content)
>       match(:method => :put).to(:action => "update").name(:update_content)
>       match(:method => :delete).to(:action => 
> "destroy").name(:destroy_content)
>       match(:method => :post).to(:action => "create").name(:create_content)
>       match(:method => :get).to(:action => "show").name(:content)
>     end
>   end
> end
>
> That "contents" special URL is due to my functional requirement that
> the /rootwould show a homepage (with an ID being set implicitly in
> the controller code), not the index of all pages.  That's also why the
> (:id) is optional.  If you wanted / to be the index you could
> rearrange some of this.  Oh, and the need for the optional (/) in
> front of 'new' but not the other methods appears to be some sort of
> edge case quirk.  It took me way too long to figure out how to make
> that work.
>
> Point is, it's still a RESTful resource.  I had to write the paths
> myself, but it all works the way Merb resources are supposed to.
>
> --
> Have Fun,
>    Steve Eley ([email protected])
>    ESCAPE POD - The Science Fiction Podcast Magazine
>    http://www.escapepod.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"merb" 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/merb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to