将值添加到现有对象以进行表单选择

时间:2014-10-26 12:50:07

标签: ruby-on-rails ruby-on-rails-4

我可以在以这种方式创建的表单中选择一组值;

@counties =   district.counties.map{|f| [f.name, f.id]}

但是,我希望添加值;

["Please select Sub-County", " "]

我试过这个没有成功,

def update_counties
    district = District.find(params[:district_id])
    @counties =  {} << ["Please select County", " "] << district.counties.map{|f| [f.name, f.id]}
    @sub_counties =  {} << ["Please select Sub-County", " "] << district.counties.first.sub_counties.map{|f| [f.name, f.id]} 
    respond_to do |format|          
      format.js { }
    end    
  end

协助?请!

1 个答案:

答案 0 :(得分:0)

@counties = [["Please select sub-county", ""]]
@counties += district.counties.map{|f| [f.name, f.id]}