2012-04-26 7 views
2

私はレールで初心者です、私は時代のこの配列を持っている:どのように文字列の配列をレールのドロップダウンに変換できますか?

[ "午前8時30"、 "9時00分"、 "9時30分"、 "10:00"、「10: 「30時」、「11時」、「11時30分」、「 」、「12時」、「13時」、「13時30分」、「14時」、 「15:00」、「 」、「15:30」、「16:00」、「16:30」、「17:00」、「17:30」、「18:00」、「18:30」、 、 "19時00分"、 "午後7時30"、 "午後08時00分"、 "夜8時30分"、 "21時"、 "21時半"]私はに変換するにはどうすればよい

options_from_collection_for_selectを使用したプルダウン。私は

<%= select_tag "start_time", options_from_collection_for_select(@start_time,:id, :name) %>

を使用してみましたが、それは"undefined method 'name' for "08:30":String"を返しました。

答えて

5

@options = ["08:30", "09:00", "09:30", "10:00", "10:30", "11:00", "11:30", "12:00", "12:30", "13:00", "13:30", "14:00", "14:30", "15:00", "15:30", "16:00", "16:30", "17:00", "17:30", "18:00", "18:30", "19:00", "19:30", "20:00", "20:30", "21:00", "21:30"] 

と仮定すると、コードが

<%= select_tag "start_time", options_for_select(@options) %> 

options_for_selectマニュアルを参照してくださいになります。

+0

感謝を次のように使用することができます。出来た! –

0

あなたは

<%= f.select :time, options_for_select(MONTHS, @job.time) %> 

ヶ月=>あなたの配列

関連する問題