質問編集履歴

2

title modified

2017/07/06 00:21

投稿

innjera
innjera

スコア132

test CHANGED
@@ -1 +1 @@
1
- プルダウンメニューをハッシュで作る
1
+ プルダウンメニューをハッシュで作る / options_from_collection_for_selectの使い方
test CHANGED
File without changes

1

修正

2017/07/06 00:21

投稿

innjera
innjera

スコア132

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,8 @@
1
1
  `db`には`integer`クラスの値を入れているが、`view`では`文字`で表示したい為、`hash`を利用しています。値の量が多いことから、選択肢を`model`内に移植しているのですが、自分のやり方だと、デフォルトで選択した値がセットされません(例えば、edit/updateの時に初期値に戻って表示される)
2
+
3
+
4
+
5
+ `options_from_collection_for_select`の`第4引数`に誤りがあるのでしょうか。
2
6
 
3
7
 
4
8
 
@@ -10,13 +14,17 @@
10
14
 
11
15
  ## データベース
12
16
 
17
+ Table name: lessons
18
+
19
+ id :integer
20
+
13
21
  price :integer
14
22
 
15
23
 
16
24
 
17
25
  ##_form.html.erb
18
26
 
19
- <%= f.select :price, options_from_collection_for_select(Lesson::PRICE_LIST, :last, :first, ), {}, {class:"form-control"}%>
27
+ <%= f.select :price, options_from_collection_for_select(Lesson::PRICE_LIST, :last, :first, params[:price] ), {}, {class:"form-control"}%>
20
28
 
21
29
 
22
30