Simply_Helpful with nested routes hack

28 Feb 2007

If you’ve played around with Simply Helpful you’ve probably enjoyed just how helpful it is. That is, until you’ve needed to use it for nested routes. As of this post Simply Helpful is in total denial of nested routes. The form_for helper just trips over itself and sprawls across your datacenter floor if you try to use it with two objects.

I enjoy the approach that this patch takes but it didn’t get committed and the code keeps on changing. Rather than attempt to chase the code with a complicated patch I’ve created a simple hack. Modifying a single line allows me to use SH in my nested-route-loving code.

form_helper_extensions.rb, line 21

    #url         = SimplyHelpful::PolymorphicRoutes.polymorphic_url(object, self)
    url         = options[:url] || SimplyHelpful::PolymorphicRoutes.polymorphic_url(object, self)

Wow. I know, it’s mind-blowing. Just pass an explicit url to form for and you’re all set.

    <%  form_for @item, :url => item_path(@project, @item) do |f| %>
    <%  end %>

Please if you found this post helpful or have questions.