Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single Table Inheritance routing?

I have single table inheritance working just fine for my app. I have two user subtypes (Athlete and Company) that inherit the super-type User.

Let's say I am listing all users, and want a link to each user's profile from this list. I want to link to the athletes controller if the type is athlete and the companies controller if the type is company. Is there a standard Rails way to this? Maybe some routing tricks?

like image 790
Sam Avatar asked Feb 18 '26 08:02

Sam


1 Answers

you can even do that much simpler, Rails recognizes which type of user it has to deal with, so let's say you have the instance variable @user wich can either be an Athlete or a Company, you can just do that

= link_to "Profile", @user

BAM! Rails magic!

like image 59
Ole Spaarmann Avatar answered Feb 20 '26 20:02

Ole Spaarmann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!