rubyの機能の実装を行なっています。
コントローラから別テーブルにあるimageのparamsを取得したいのですが、何故か上手く行きません。
attributesメソッドを使って試してはいるのですが、取得できない状態です。
まだまだ若輩者ですが、ご教授いただければ幸いです。
よろしくお願いします。
DBのアソシエーションは組んでおり、imageのモデルにmount_uploader :image, ImageUploaderを記入済みです。
html
1 <div class="sell-dropbox-container clearfix"> 2 <div class="sell-upload-items have-item", id="items"> 3 <ul id="item"> 4 <li class="sell-upload-item"> 5 <%= form_for @item do |f| %> 6 <div class="sell-upload-item-1"> 7 <%= f.fields_for :item_images do |image| %> 8 <figure class="sell-upload-figure figure-1"> 9 <img> 10 <input type="file" class="sell-upload-drop-file" multiple="multiple" name="image" style="display: none"> 11 <pre class="visible-pc-1">ドラッグアンド<br>ドロップ<br>またはクリックして<br>ファイルを<br>アップロード</pre> 12 <%= image.file_field :image, :multiple => true %> 13 </figure> 14 <% end %> 15 </div> 16 <% end %> 17 </li> 18 </ul> 19 </div> 20 </div>
ruby
1class ItemsController < ApplicationController 2 3 def index 4 end 5 6 def new 7 @item = Item.new 8 @item.item_images.build 9 end 10 11 def show 12 end 13 14 def create 15 @item = Item.new(item_params) 16 binding.pry 17 end 18 19 def purchase 20 end 21 22 def purchased 23 end 24 25 private 26 27 def item_params 28 params.require(:item).permit( 29 :name, 30 :introduction, 31 :price, 32 item_images_attributes: :image 33 ) 34 end 35 36end
jQuery
1$(function(){ 2 $(document).on("change", ".figure-1", function(e){ 3 var file = e.target.files[0]; 4 if (file === undefined){ 5 return ; 6 } 7 $(".visible-pc-1").text(""); 8 $(".figure-1").children("input").remove(); 9 var html = buildIMAGE1() 10 $(".sell-upload-item-1").append(html) 11 var reader = new FileReader(); 12 var IdentifiedImg = $(this).children("img"); 13 14 reader.onload = (function(file){ 15 return function(e){ 16 IdentifiedImg.attr("src", e.target.result); 17 IdentifiedImg.attr("title", file.name); 18 }; 19 }) (file); 20 reader.readAsDataURL(file); 21 }); 22});
回答2件
あなたの回答
tips
プレビュー