Rails Polymorphic relationship and link_to?

You could do something like this: def my_menu_url(menu) "/#{menu. Menuable_type. Tableize}/#{menu.

Menuable_id}" end if you use the rails convention for naming the controllers that correspondent to your models But don't do it. You work around the routing mechanism of rails and that's simply bad practice You should use the :include option in your finders to eager load your menuables: Menu. All :include => :menuable In the case this isn't enough you may use some sort of caching.

You could do something like this: def my_menu_url(menu) "/#{menu. Menuable_type. Tableize}/#{menu.

Menuable_id}" end if you use the rails convention for naming the controllers that correspondent to your models. But don't do it. You work around the routing mechanism of rails and that's simply bad practice.

You should use the :include option in your finders to eager load your menuables: Menu. All :include => :menuable In the case this isn't enough you may use some sort of caching.

– tchen Aug 16 '09 at 10:10 I guess at most you can reduce the loading to the number of polymorphic types that exist. Unfortunately, a quick search shows that this is not the existing behavior in ActiveRecord. :( Maybe it's time to go back to single table inheritance.

– tchen Aug 16 '09 at 10:15 I think ActiveRecord first loads all the Menu records.In a second step it dos a query for every menuable_type in the result set of the first query. I think single table inheritance is no solution in this case, because the tow models differ to much. – gregor Aug 16 '09 at 19:03.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions