質問編集履歴
6
タグ追加
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
5
大幅改訂
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Rails: form_for / file_fieldの
|
1
|
+
Rails: form_for / file_fieldへのclass指定
|
test
CHANGED
@@ -1,81 +1,133 @@
|
|
1
|
-
Rails 5.0.0.1で開発しています。
|
2
|
-
|
3
|
-
ファイル uploadに際し、carrierwaveを用いています。
|
4
|
-
|
5
|
-
UIでDrag & Dropできる仕様とするべく、[dropzonejs](http://www.dropzonejs.com/)(ruby-gem:dropzonejs-rails)を入れています。
|
1
|
+
Rails 5.0.0.1、ファイル upload:carrierwave、UIでDrag & Dropをできる仕様とするべく、[dropzonejs](http://www.dropzonejs.com/)(ruby-gem:dropzonejs-rails)を入れています。
|
6
2
|
|
7
3
|
|
8
4
|
|
5
|
+
以下の通り画像(ファイルアップロード)のみであれば問題なく動きますが、画像(ファイル)のみならず、model内のその他のカラム(例えば、`string`のタイトル等)を加えると、入れると、viewで出したい画面が出なくなります。
|
6
|
+
|
9
|
-
|
7
|
+
サーバー側での問題ではなく、単純に`class`の指定に問題があると思っていますが、直し方が分からず、誤りをご指摘頂けますと助かります。
|
10
8
|
|
11
9
|
|
12
10
|
|
11
|
+
###問題なく表示されるコード
|
12
|
+
|
13
|
+
```html
|
14
|
+
|
15
|
+
#erbファイル
|
16
|
+
|
13
|
-
|
17
|
+
<%= form_for [:user, @product], url: :user_user_product,
|
18
|
+
|
19
|
+
html: {multipart: true, class: 'dropzone', id: 'my-dropzone'} do |f| %>
|
20
|
+
|
21
|
+
<div class = "fallback">
|
22
|
+
|
23
|
+
<%= f.file_field :makeimg_three %>
|
24
|
+
|
25
|
+
<%= f.submit "編集する" %>
|
26
|
+
|
27
|
+
</div>
|
28
|
+
|
29
|
+
<% end %>
|
14
30
|
|
15
31
|
|
16
32
|
|
17
|
-
|
33
|
+
#生成されるhtml
|
18
34
|
|
35
|
+
<form class="dropzone" id="my-dropzone" enctype="multipart/form-data" action="/user/users/2/products/4" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="✓" /><input type="hidden" name="_method" value="patch" /><input type="hidden" name="authenticity_token" value="itPqv0HfK1eTIIJCca3ug8Zfpj9zd73BLkhjBExnHS42dU7fKwb3F9LFU+FaKcp61wbxhXAeRBiuRZcnkCUH9Q==" />
|
19
36
|
|
37
|
+
<div class = "fallback">
|
20
38
|
|
39
|
+
<input type="file" name="product[makeimg_three]" id="product_makeimg_three" />
|
21
40
|
|
22
|
-
|
23
|
-
```html
|
24
|
-
|
25
|
-
#edit.html.erb
|
26
|
-
|
27
|
-
<%= form_for [:user, @product], url: :user_user_product do |f| %>
|
28
|
-
|
29
|
-
<%= render "form", f: f %>
|
30
|
-
|
31
|
-
<%= f.submit "編集する" %>
|
32
|
-
|
33
|
-
<% end %>
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
#_form.html.erb
|
38
|
-
|
39
|
-
<
|
41
|
+
<input type="submit" name="commit" value="編集する" data-disable-with="編集する" />
|
40
|
-
|
41
|
-
<div class="fallback">
|
42
|
-
|
43
|
-
<%= f.file_field :makeimg_three, :class => 'fallback' %>
|
44
42
|
|
45
43
|
</div>
|
46
44
|
|
47
|
-
|
45
|
+
</form>
|
48
46
|
|
49
47
|
```
|
50
48
|
|
51
49
|
|
52
50
|
|
53
|
-
|
51
|
+
###うまくいかないコード(単純にmodelのカラムを追加しただけです)
|
52
|
+
|
53
|
+
うまくいく方は`form_for`に`class:'dropzone'`を指定していますが、そのままだとおかしな表示になってしまう為、外に出しているのですが、当然かもしれませんが、機能しなくなります。
|
54
54
|
|
55
55
|
```html
|
56
56
|
|
57
|
-
|
57
|
+
#erbファイル
|
58
58
|
|
59
|
-
|
59
|
+
<%= form_for [:user, @product], url: :user_user_product,
|
60
60
|
|
61
|
+
html: {multipart: true} do |f| %>
|
62
|
+
|
63
|
+
<div class="form-group row">
|
64
|
+
|
61
|
-
<i
|
65
|
+
<%= f.label :title, "コース", class: "col-form-label form-adj required", style:"font-size:1rem;" %>
|
66
|
+
|
67
|
+
<div class="form-adj-latter">
|
68
|
+
|
69
|
+
<%= f.text_field :title, class:"form-control", type:"text", placeholder:"例:目元が映えるメイク" %>
|
70
|
+
|
71
|
+
</div>
|
62
72
|
|
63
73
|
</div>
|
64
74
|
|
75
|
+
<div class="dropzone", id:'my-dropzone'>
|
76
|
+
|
77
|
+
<div class = "fallback">
|
78
|
+
|
79
|
+
<%= f.file_field :makeimg_three %>
|
80
|
+
|
81
|
+
<%= f.submit "編集する" %>
|
82
|
+
|
83
|
+
</div>
|
84
|
+
|
85
|
+
</div>
|
86
|
+
|
87
|
+
<% end %>
|
65
88
|
|
66
89
|
|
67
|
-
|
90
|
+
|
91
|
+
#生成されるhtmlファイル
|
92
|
+
|
93
|
+
<form class="edit_product" id="edit_product_4" enctype="multipart/form-data" action="/user/users/2/products/4" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="✓" /><input type="hidden" name="_method" value="patch" /><input type="hidden" name="authenticity_token" value="kw+KGD28O9Yt16m95DuUKxyLnHN01UDtZm9dbuYYpn4vqS54V2XnlmwyeB7Pv7DSDdLLyXe8uTTmYqlNOlq8pQ==" />
|
94
|
+
|
95
|
+
<div class="form-group row">
|
96
|
+
|
97
|
+
<label class="col-form-label form-adj required" style="font-size:1rem;" for="product_title">コース</label>
|
98
|
+
|
99
|
+
<div class="form-adj-latter">
|
100
|
+
|
101
|
+
<input class="form-control" type="text" placeholder="例:目元が映えるメイク" value="ttファンデーションの基礎教えます" name="product[title]" id="product_title" />
|
102
|
+
|
103
|
+
</div>
|
104
|
+
|
105
|
+
</div>
|
106
|
+
|
107
|
+
<div class="dropzone", id:'my-dropzone'>
|
108
|
+
|
109
|
+
<div class = "fallback">
|
110
|
+
|
111
|
+
<input type="file" name="product[makeimg_three]" id="product_makeimg_three" />
|
112
|
+
|
113
|
+
<input type="submit" name="commit" value="編集する" data-disable-with="編集する" />
|
114
|
+
|
115
|
+
</div>
|
116
|
+
|
117
|
+
</div>
|
68
118
|
|
69
119
|
</form>
|
70
120
|
|
71
121
|
```
|
72
122
|
|
73
|
-
実際の画面
|
74
123
|
|
124
|
+
|
125
|
+
問題ない方の画面はこちら
|
126
|
+
|
75
|
-
![
|
127
|
+
![イメージ説明](14af30c63d8ce26519d79869007a6a89.png)
|
76
128
|
|
77
129
|
|
78
130
|
|
79
|
-
|
131
|
+
問題ある方の画面はこちら
|
80
132
|
|
81
|
-
![イメージ説明](
|
133
|
+
![イメージ説明](164f68df1dd932efea2c535722c90468.png)
|
4
tag追加
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
3
tag追加
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
2
誤字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -66,7 +66,7 @@
|
|
66
66
|
|
67
67
|
<input type="submit" name="commit" value="編集する" data-disable-with="編集する" />
|
68
68
|
|
69
|
-
</form>
|
69
|
+
</form>
|
70
70
|
|
71
71
|
```
|
72
72
|
|
1
shuusei
test
CHANGED
File without changes
|
test
CHANGED
@@ -72,7 +72,7 @@
|
|
72
72
|
|
73
73
|
実際の画面
|
74
74
|
|
75
|
-
![![イメージ説明](54ee0d00366441670d4b3640d3002046.png)]
|
75
|
+
![![イメージ説明](54ee0d00366441670d4b3640d3002046.png)]
|
76
76
|
|
77
77
|
|
78
78
|
|