Ruby on Rails初心者です。
ユーザーがzipファイルを入力すると、controllerで展開して個々の画像ファイルにした後、DBに保存せずにさらにviewに渡して、そこで画像ファイルをユーザーが並び替えてimage1 ~ image30カラムに保存する機能を作りたいと思っています。
しかし、
controllerでDBに保存せずにさらにviewに渡すことができずに困っています。
環境
macOS High Sierra(バージョン10.13.6)
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin17]
Rails 4.2.6
##現状のコード
# view <%= form_for([:manage,@product], url: { action: "unzip"}) do |f| %> <p class="row" id="js-selectFile"> <%= f.label :fake_zip %> <%= f.file_field :fake_zip %> <button class="original-btn">ZIPファイルを選択</button> </p> <div class="actions"> <%= button_tag type: 'submit' do %> <i class="fa fa-pencil" aria-hidden="true"></i> 作成 <% end %> </div> <% end %>
ruby
1def unzip 2 @product = Product.new(product_params) 3 zipfile = product_params[:fake_zip] 4 Zip::File.open(zipfile.path) do |zip| 5 num = 0 6 zip.each do |entry| 7 ext = File.extname(entry.name) #拡張子を取得 8 # 隠しファイルやゴミファイルは飛ばす 9 next if ext.blank? || File.basename(entry.name).count(".") > 1 10 11 num += 1 12 if num > 30 then 13 break 14 end 15 16 # 一時ファイルを作る 17 Tempfile.open(["tempProductImageFile", ext]) do |t| 18 entry.extract(t.path) { true } 19 @product.send("products_image#{num}=", t) 20 end 21 end 22 end 23 #ここからの処理がわからない 24 end
知りたいこと
上記のunzipアクションの実行と同時に別のビューを表示させて、その中で展開したファイルを一つずつ表示させることは可能でしょうか?可能であれば方法を知りたいです。
また何か他の方法があれば、ご教示の方、何卒よろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。