On 15.9.2005, at 18.55, Adam Denenberg wrote:
> Hello,
>
> I have a situation as follows in a DB relationship.
>
> Manufacturers ==> ID / Name
> Models ==> ID / Name / Manufacturer_id
>
> Nodes ==> ID / Name / Model_ID
>
> I am setting up an inventory where each node is a certain type of
> manufacturer/model. One manufacturer can have many models. So in
> my nodes database I only put a relationship to the model_id, since
> from the model_id i can determine the Manufacturer. What is the
> best way to code this in say a form ?
>
> What i want is say, when a user changes the Manufacturer in a "New
> Node Form", i find all the models for that manufacturer in a
> dropdown in the new.rhtml form.. Is there a way to handle this in
> the model definition somehow automatically ?
Adam,
This is just a presentation problem if you have your database setup
as above and ActiveRecord accordingly:
Manufacturer has_many :models
Model belongs_to :manufacturer
has_many :nodes
Node belongs_to :model
Now you can put a select dropdown for manufacturers to the form and
use AJAX to bring another dropdown with the models to the page when a
manufacturer is selected. You can use e.g. observe_field helper [1]
for that or put the "new Ajax.updater" javascript call in an event
handler [2] of the first field.
//jarkko
[1] http://rails.rubyonrails.com/classes/ActionView/Helpers/
JavaScriptHelper.html#M000402
[2] like onChange: http://www.devguru.com/Technologies/ecmascript/
quickref/evhan_onchange.html
>
> thanks
> adam
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails