Polymorphic_routes has_one

So in my config/routes.rb I have :

map.resources :product_lines, :has_many =>
[:products, :documents], :has_one => :image

Note: Images are polymorphic (imageable)

In my images controller I have:

def new
@imageable = polymorphic_parent(params)
@image = Image.new

The polymorphic_parent function just looks through the params and
finds one with _id and finds the parent instance of the polymorphic
relationship. So, in app/controllers/application.rb I have:

def polymorphic_parent(params)
for key, param in params
if key.match(/_id$/)
klass = key[0…key.length - 3].classify
return eval("#{klass}.find(param)")
end
end
end

And in my app/views/images/new.html.erb I have:

<% form_for([@imageable, @image], :html => { :multipart => true }) do |
f| %>
… etc…

But it throws and error because I guess polymorphic_routes doesn’t
work with has_one…

undefined method `product_line_images_path’ for #<ActionView::Base:
0xb620f970>

I think the path should be product_line_image_path (image not images).
Does anybody know If I can make this work? Am I doing something
wrong?

Thanks

Well, it seems with edge rails there may have been an attempt to fix
this. From actionpack/CHANGELOG:

Fix polymorphic_url with singleton resources. #461 [Tammer Saleh]

I’m not sure what this patch intended to do, but from looking at the
tests I guess I’m supposed to use a symbol to denote a singular
resource. That does not seem to work with form_for though because
form_for needs an object instance to be passed to the block. Note:
This all works fine with a has_many nested resource.

It’s very strange to me that all of the routing is set up in routes.rb
but then none of that information seems to be available to the url/
path helpers…