I’m somewhat new to RoR and can’t seem to find a solution to an issue
I’m having. Assuming I have two tables: frogs and frog_pairs that are
setup like so
frogs
- id int(11)
- name varchar(50)
frog_pairs
- id int(11)
- species_friend int(11) (foreign key)
- species_foe int(11) (foreign key)
I know that Rails would rather see ‘frog_id’ as a foreign key inside the
frog_pairs table in order to make an associating to the frogs table,
but I need to actually create a “pair” based on two frogs.
I have been able to successfully add a frog pair to frog_pairs by
inserting two differnt id’s from frogs, but how would I go about
putting the two frog (names) out to my view…
I want my (list) view to look like this:
Frog Pair Listings
id species_friend species_foe
- 1 African Dwarf Poison Dart
- 2 Argentine Horned Fire-bellied
but it looks like this right now:
Frog Pair Listings
id species_friend species_foe
- 1 2 5
- 2 3 1
…and I’d like to have my (show) view look like this:
Showing Frog Pair 2
Species Friend
- Argentine Horned
Species Foe
- Fire-bellied
…instead of the obvious:
Showing Frog Pair 2
Species Friend
- 3
Species Foe
- 1
If this is something I have to override RoR’s foreign key behavior or
use something like find_by_sql, could anyone provide an explicit example
from model to controller to view? Thanks!
(I hope I have not confused everybody more than I am already!)