お世話になります。
画像投稿アプリ作成中です。
今回carrierwaveを使いが画像投稿機能を作成した所がぞうが表示されませんでした。
![
全てのファイルをここに記述するのは難しいので関係有りそうなファイルのみ載せておきます。
考えられる原因を教えてください。
workspace\photogenic\app\models\picture.rbファイル
ruby
1class Picture < ActiveRecord::Base 2 validates :title, :content, :photo_image,presence: true 3 belongs_to :user 4 mount_uploader :picture,PictureUploader 5end 6
workspace\photogenic\app\uploaders\picture_uploader.rbファイル
ruby
1class PictureUploader < CarrierWave::Uploader::Base 2 # Include RMagick or MiniMagick support: 3 # include CarrierWave::RMagick 4 # include CarrierWave::MiniMagick 5 6 # Choose what kind of storage to use for this uploader: 7 storage :file 8 9 process convert: 'jpg' 10 11 def filename 12 super.chomp(File.extname(super)) + '.jpg' if original_filename.present? 13 end 14 # storage :fog 15 def extension_white_list 16 %w(jpg jpeg gif png) 17 end 18 # Override the directory where uploaded files will be stored. 19 # This is a sensible default for uploaders that are meant to be mounted: 20 def store_dir 21 "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 22 end 23 24end
workspace\photogenic\app\views\pictures_form.html.erbファイル
ruby
1<!-- ここから追加 --> 2<%= form_for(@picture, html: {multipart: true}) do |f| %> 3<!-- ここまで追加 --> 4 5 <% if @picture.errors.any? %> 6 <div id="error_explanation" class="alert alert-danger"> 7 <h2><%= pluralize(@picturet.errors.count, "error") %> prohibited this post from being saved:</h2> 8 9 <ul> 10 <% @picturet.errors.full_messages.each do |message| %> 11 <li><%= message %></li> 12 <% end %> 13 </ul> 14 </div> 15 <% end %> 16 17<!-- ここから追加 --> 18 <div class="field"> 19 <%= f.label :photo_image %> 20 <%= f.file_field :photo_image %> 21 </div> 22<!--ここまで追加--> 23 24 <div class="field"> 25 <%= f.label :title %><br> 26 <%= f.text_field :title %> 27 </div> 28 <div class="field"> 29 <%= f.label :content %><br> 30 <%= f.text_area :content %> 31 </div> 32 <div class="actions"> 33 <%= f.submit %> 34 </div> 35<% end %>
情報が少ないかもしれませんが、ありがちな失敗などでも構いません。
宜しくお願い致します。
参考にしたサイトや書籍などがありましたらご教示ください。
回答1件
あなたの回答
tips
プレビュー