https://gyazo.com/6bb8d731146016c8e7489140d424e722
上はスクショです
undefined method `each' for #ImageUploader:0x00007f50440dd180
Extracted source (around line #15):
13
14
15
16
17
18
<div class="feature-image"> <% @information.image.each do |image| %> <%= image_tag(@information.image_url) %> <% end %> </div>
というエラーが出てしまいます
http://arthurxxx.hatenablog.com/entry/2018/02/05/234638
このサイトを参考にし、複数の画像を投稿できるようにしようと思いました
以下imageに関係するものだけ載せさせていただきます
show.html.erb
ruby
1<div class="feature-image"> 2 <% @information.image.each do |image| %> 3 <%= image_tag(@information.image_url) %> 4 <% end %> 5 </div>
new.html.erb
ruby
1<div class="pv4"> 2 <%= render 'form', information: @information %> 3</div>
_form.html.erb
ruby
1<div class="field"> 2 <div class="control"> 3 <label class="label">Add images</label> 4 <div class="file"> 5 <label class="file-label"> 6 <%= f.input :image, as: :file, input_html: { class:"file-input instrument-image" }, label: false, wrapper: false, :multiple => true %> 7 <span class="file-cta"> 8 <span class="file-icon"><i class="fa fa-upload"></i></span> 9 <span class="file-label">Choose a file…</span> 10 </span> 11 </label> 12 </div> 13 </div> 14 </div> 15 <output id="list"></output> 16 <hr />
マイグレーションファイル
ruby
1class AddImageToInformation < ActiveRecord::Migration[5.2] 2 def change 3 add_column :information, :image, :string 4 end 5end
information.rb
ruby
1mount_uploader :image, ImageUploader 2 serialize :image, JSON
となっています。教えてください!
さらに:imageを{image: []}とするとNil location provided. Can't build URI.となってしまいます(show,indexページで)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/09 05:20
2019/06/09 06:56
2019/06/09 08:06
2019/06/10 05:30
2019/06/10 06:19
2019/06/10 10:47
2019/06/10 12:17
2019/06/10 12:50
2019/06/10 13:33
2019/06/11 01:22
2019/06/11 01:49
2019/06/11 04:33
2019/06/11 04:37
2019/06/17 10:47
2019/06/27 22:29