Reputation: 14515
I'm having issues displaying the thumbnail of my uploaded image. A file successfully uploads but I have been unable to display it. Any attempt to find the url or path throws undefined method errors. Really appreciate any and all help!
Model
class Play < ActiveRecord::Base
mount_uploaders :profile_images, ImageUploader
end
controller
...
def play_params
params.require(:play).permit(:title, :description, :date_of_play,:profile_image)
end
...
Uploader
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb do
process :resize_to_limit => [200, 200]
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
views/plays/_form.html.erb
...
<%= f.file_field :profile_image %>
...
views/plays/show.html.erb
...
<%= image_tag @play.profile_image.url(:thumb) if @play.profile_image.present? %>
...
migration
class CreatePlays < ActiveRecord::Migration
def change
create_table :plays do |t|
t.string :title, null: false
t.string :description, null: false
t.datetime :date_of_play, null: false
t.string :profile_image
t.timestamps null: false
end
end
end
error
undefined method `url' for "#<File:0x00000005a7dbb8>":String
Thanks!
Upvotes: 0
Views: 187
Reputation: 1387
You should change
mount_uploaders :profile_images, ImageUploader
to
mount_uploader :profile_image, ImageUploader
Refer to the CarrierWave documentation, you have just mixed up single and multiple file uploads configuration.
Upvotes: 1