我是ruby on rails的新手。我想从模型
填充下拉列表 <%= collection_select(nil, :entity_id, @entity, :id, :name,
{:prompt => "Select an Entity"}, {:id => 'entity_select'}) %>
基于另一个下拉列表
<%= collection_select(nil, :project_id, @projects, :id, :name,
{:prompt => "Select a Project"} %>
在选择项目时,需要在下拉列表中显示相应的实体,但我会显示实体表中的所有实体。我不知道Ajax。还有其他简单的方法吗?
答案 0 :(得分:1)
对于这种特殊情况,使用grouped_collection_select
会很好。
更多详情请见Rails API Doc
另请考虑观看Ryan Bates的详细Railscast
答案 1 :(得分:0)
试试这个:
collection_select(nil, :entity_id, Entity.all, :id, :name, :prompt => "Select an Entity")