On 2 Oct 2007, at 01:45, hebertodelrio wrote:
>
> Hi, I am a newbie in RoR, really newbie, I have followed some of the
> tutorials, and now it is time for me to start one of my own.
>
> To simplify the set-up, I have a client that has let us say a
> pharmacy, the problem boils down to having three tables, BRAND, ACTIVE
> INGREDIENT, and MEDICAL CONDITION. These three table are related to
> each other. A brand can have many products each having only one active
> ingredient, but each active ingredient treats different medical
> conditions. (the example is not quite exact, because why should a
> brand carry more than one medicine with the same active ingredient,
> but just follow me for the sake of the example).
>
>
You can use a field observer (see the observe_field helper) to
trigger an ajax call every time the selection changes. if you''ve got
your has_manys and has_many :through relationships set up properly it
should reasonably straight forward from here.
eg
class Brand < ActiveRecord::Base
has_many :products
has_many :active_ingredients, :through => :products
has_many :medical_conditions, :through => :active_ingredients
end
class MedicalCondition
has_many :active_ingredient_medical_conditions
has_many :active_ingredients, :through
=> :active_ingredient_medical_conditions
has_many :products, :through => :active_ingredients
end
having picked a given brand, you can then restrict the active
ingredients list to brand.active_ingredients etc, or given a medical
condition, medical_condition.products is the list of those products
that can treat it.
Fred
> I need help!!!!
>
> Heberto del Rio
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---