简体   繁体   English

Rails:我想基于逻辑限制form.html.erb中可用的选择

[英]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] 说我有[班级] has_many [订单] has_many [家庭]
(Remember old-school version of Kingdom Phylum Class Order Family Genus Species?) (还记得老版本的王国Phylum类订单家庭属物种吗?)

When the data-entry person has previously selected, say, the four-legged mamals [Class], 当数据输入人员先前选择了四足哺乳动物 [Class],

and the Canids [Order] (I have no clue if this is at all right, but I hope you get the point), Canids [Order](我完全不知道这是否可以,但是希望您能理解 ),

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: 我假设您要像这样绘制“ Family选择框:

<%= 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 : 但是鉴于用户已经选择了一个订单(假设您已将该对象实例化为@order

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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