0
我是rails新手,需要一些幫助來迭代sql結果。Rails - 將find_by結果迭代到select下拉列表
我在我的模型中使用的方法find_by:
def self.find_country()
@countries = CountryTable.find_all_by_country_status('Y', :select => "country_name")
@countries.each do |c|
puts "#{c.inspect}"
end
end
這是我的觀點:
<%= select_tag "country", options_for_select(CountryTable.find_country) %>
然後我得到這個尷尬#< CountryTable:0x30509bc >代替國家名稱顯示爲源中的每個選項:
<option value="#<CountryTable:0x30509bc>">#<CountryTable:0x30509bc></option>
<option value="#<CountryTable:0x3050944>">#<CountryTable:0x3050944></option>
<option value="#<CountryTable:0x30508e0>">#<CountryTable:0x30508e0></option>
我對軌道很陌生,以至於我甚至可能不會去做這個事情。
感謝mckeed,這工作完美! – oprogfrogo 2010-09-17 19:32:39