简体   繁体   中英

Rails: I want to limit the selections available in form.html.erb based on logic

I need to reduce the selectable items to what is appropriate considering what was previously established.

Say I have [Class] has_many [Order] has_many [Family]
(Remember old-school version of Kingdom Phylum Class Order Family Genus Species?)

When the data-entry person has previously selected, say, the four-legged mamals [Class],

and the Canids [Order] (I have no clue if this is at all right, but I hope you get the point),

They should just get Wolves, Foxes, and Dogs, etc. as their choices since they've narrowed it down that far.
I don't want to give the operator a list of [Families] like Cats or Crows or Crocodiles.

How do I go about that?

I'd assume you're trying to draw, say, the Family select box like this:

<%= collection_select :family_id, Family.all, :id, :name %>

But given that the user has already selected an order (let's assume you've instantiated that object as @order :

<%= collection_select :family_id, @order.families, :id, :name %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM