# Cross linking controllers & polyporhism

**URL:** <https://www.ruby-forum.com/t/cross-linking-controllers-polyporhism/105461>\
**Category:** Rails\
**Created:** [May 30, 2007, 7:18am UTC](https://www.ruby-forum.com/t/cross-linking-controllers-polyporhism/105461 "2007-05-30T07:18:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 30, 2007, 7:18am UTC](https://www.ruby-forum.com/t/cross-linking-controllers-polyporhism/105461/1 "2007-05-30T07:18:24Z")

</div>

Alright, so this problem is two fold. One probably has a simple  
answer…

And the other probably has a simple answer…

Maybe not.

1. I have many different controllers… three of note would be  
‘order’, ‘review’ & ‘quote’.

if im in viewing “/orders/list” i would like to generate a link to go  
to the corresponding review & quote.

can a generic link\_to be somehow cajoled into going to “/reviews/show/  
23432” where 23432 is the review\_id of the order?

problem 2) i can think of a million and one kludgy ways to do this but  
none of them seem to be good rails form…

the same app has a model for inspection sheets. each order is assigned  
an inspection sheet and each inspection sheet has multiple validated  
fields which are created by whoever approves the order… for  
example… (and believe me, this is a gross oversimplification)

order #23432 is for a custom made, standard square box.

the boxes will be made by hand and each operator is going to check for  
4 things.

length, width and height of the box, limits specified at order time  
visual inspection

heres where i think polymorphism might be a good solution, just dont  
know how to properly implement it…

the length width and height are all numbers with a given range. when  
the inspected boxes are out of that range i’ll raise some kind of  
error or something…

the visual inspection (and many other types of fields) are booleans…  
go/no go… good/no good… etc…

my original scheme went something like this…

inspection\_sheets: table containing all sheet\_id’s and their  
corresponding orders.

inspection\_sheet\_fields: a table to hold all the definition fields as  
users create them for new inspection sheets… it would have a  
sheet\_id, field\_name…eg “length”, and in the case of numerical  
input… a max\_value and a min\_value… or in the case of booleans…  
just a good\_value…

lastly,

inspection\_sheet\_rows: a table which would contain a sheet\_id,  
field\_id and a “measured\_value” or some such… to hold the physical  
value measured.

now if you ask me, that last table, especially that last table - will  
get filled up in quite a hurry… but thats another bridge to cross at  
another time… not to mention the cost of re-evaluating the entire  
insepction sheet every time someone one wants to do “inspection\_sheets/  
show/23432”…

im just looking for some suggestion on how to do this rubily…

thanks for the input.  
-FJM

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 30, 2007, 7:24am UTC](https://www.ruby-forum.com/t/cross-linking-controllers-polyporhism/105461/2 "2007-05-30T07:24:25Z")

</div>

1. link\_to :controller =\> “order”, :action =\> “show”, :id =\>  
review.id (or whatever the id is)

2. Im confused about re-evaluating everytime someone show’s, evaluate  
on save, not on view? Also, on the validations. You may find this  
useful:[http://feeds.feedburner.com/~r/RyansScraps/~3/120631326/what-s-](http://feeds.feedburner.com/~r/RyansScraps/~3/120631326/what-s-)  
new-in-edge-rails-validates\_numericality\_of-gets-pimped

Cheers,  
Zach I.  
â†’ Blog – [http://www.zachinglis.com](http://www.zachinglis.com)  
â†’ Company – [http://www.lt3media.com](http://www.lt3media.com)  
â†’ Portfolio – [http://portfolio.zachinglis.com](http://portfolio.zachinglis.com)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 30, 2007, 7:43am UTC](https://www.ruby-forum.com/t/cross-linking-controllers-polyporhism/105461/3 "2007-05-30T07:43:26Z")

</div>

Thanks for the help Zach,  
It occurred to me about 3 seconds after I posted it that :controller  
=\> was the one thing I didn’t try… Heh, I knew it had to be easy.

And those additions to validates\_numerically\_of are certainly helpful.  
Now the fun part seems like figuring out how to store each fields  
necessary type of VNO and recalling it. It’s gonna be a long week.

Here’s a question for you. The relationship between each fields  
“definition” field and its corresponding inspection field… would you  
say that the definition field HABTM inspections or just that each  
inspection has\_one definition?

Is there a large difference?
