回答編集履歴
5
うーん
answer
CHANGED
@@ -43,6 +43,7 @@
|
|
43
43
|
```ruby
|
44
44
|
application_helper.rb
|
45
45
|
def file_input_jbuilder(images)
|
46
|
+
images=Array(images)
|
46
47
|
({"initialPreview"=>images.map{|image|image.thumb.url},
|
47
48
|
"initialPreviewAsData"=>true,
|
48
49
|
"initialPreviewConfig"=>images.map{|image| {"caption"=>image.original_filename,"width"=> '120px',"url"=> url_for({controller: :images,action: :delete,id: image.id}),"key"=> 100}}}).to_json
|
4
Test
answer
CHANGED
@@ -28,16 +28,12 @@
|
|
28
28
|
<%= from_for(@shop) do |f| %>
|
29
29
|
<%= f.text_fields :shopname %>
|
30
30
|
~
|
31
|
-
|
31
|
+
<%= f.fields_for :images_attributes do |image| %>
|
32
|
-
<%=
|
32
|
+
<%= image.file_field :file,class: 'file-upload',name: "#{image.object_name}[file]",'data-json'=>file_input_jbuilder(image.object.file) %>
|
33
33
|
<%= javascript_tag do %>
|
34
34
|
$(".file-upload").fileinput($(this).data('json'));
|
35
35
|
<% end %>
|
36
36
|
```
|
37
|
-
fields_for を使うときは
|
38
|
-
name: "shop[images_attributes][][file]"
|
39
|
-
を
|
40
|
-
name: "#{f.object_name}[images_attributes][][file]"
|
41
37
|
|
42
38
|
|
43
39
|
jbuilderがうまく使えなかったのでto_jsonで妥協
|
3
すみません
answer
CHANGED
@@ -49,7 +49,7 @@
|
|
49
49
|
def file_input_jbuilder(images)
|
50
50
|
({"initialPreview"=>images.map{|image|image.thumb.url},
|
51
51
|
"initialPreviewAsData"=>true,
|
52
|
-
"initialPreviewConfig"=>
|
52
|
+
"initialPreviewConfig"=>images.map{|image| {"caption"=>image.original_filename,"width"=> '120px',"url"=> url_for({controller: :images,action: :delete,id: image.id}),"key"=> 100}}}).to_json
|
53
53
|
end
|
54
54
|
```
|
55
55
|
最後にコントローラのstrong_paramaterを修正
|
2
修正
answer
CHANGED
@@ -49,7 +49,7 @@
|
|
49
49
|
def file_input_jbuilder(images)
|
50
50
|
({"initialPreview"=>images.map{|image|image.thumb.url},
|
51
51
|
"initialPreviewAsData"=>true,
|
52
|
-
"initialPreviewConfig"=>attachments.map{|image| {"caption"=>image.original_filename,"width"=> '120px',"url"=> url_for{controller: :images,action: :delete,id: image.id},"key"=> 100}}}).to_json
|
52
|
+
"initialPreviewConfig"=>attachments.map{|image| {"caption"=>image.original_filename,"width"=> '120px',"url"=> url_for({controller: :images,action: :delete,id: image.id}),"key"=> 100}}}).to_json
|
53
53
|
end
|
54
54
|
```
|
55
55
|
最後にコントローラのstrong_paramaterを修正
|
1
修正
answer
CHANGED
@@ -49,7 +49,7 @@
|
|
49
49
|
def file_input_jbuilder(images)
|
50
50
|
({"initialPreview"=>images.map{|image|image.thumb.url},
|
51
51
|
"initialPreviewAsData"=>true,
|
52
|
-
"initialPreviewConfig"=>attachments.map{|image| {"caption"=>image.original_filename,"width"=> '120px',"url"=> url_for{controller: :
|
52
|
+
"initialPreviewConfig"=>attachments.map{|image| {"caption"=>image.original_filename,"width"=> '120px',"url"=> url_for{controller: :images,action: :delete,id: image.id},"key"=> 100}}}).to_json
|
53
53
|
end
|
54
54
|
```
|
55
55
|
最後にコントローラのstrong_paramaterを修正
|