link_to when using STI --> undefined method `animal_path'

hi,

im getting started with STI but having trouble with link_to

Model Animal

including an type column

  1. routes:

resource :animal

resources :tiger , :controller => ‘animals’, type: ‘tigler’

resources :lion , :controller => ‘animals’, type: ‘lion’

  1. index.html

link_to ‘show’, animal >>undefined method `animal_path’

what is the correct way without hacking through classes and rewriting url helpers etc?

thx

animal_path won't work because you've commented out resource :animal (which should be plural anyway, as should the others).

its just pseudo-code.

but if i leave the base resource in there, then it give me an /animal/id route which i dont want. i want either /tiger/id or lion/id

thx

Then you need to know whether your animal is a tiger or lion (or bear of course), and call the appropriate path helper. That kind of messiness is exactly what inheritance (and other forms of polymorphism) are great at solving.

correct. i am experimenting with polymorphic_path(resource) and eg polymorphic_url([blog, post]), but so far im not getting the result i want. i am having separate files and inherited models and also inherited controllers (those dont have eny defined actions yet)…but no go…