I am new to rails and I am trying to use the carrierwave gem to upload files onto my system. I have done all of the steps but struggling with how to code it so I am able to view it on my system without an error.
I have previously tried adding
show.html.erb:
<%= attachment_tag @post.attachment.url, class: "post-show" %>
but receive the error
"undefined method `attachment_tag' for #<#<Class:0xb646078>:0xb8bb8b0>"
posts.rb:
class Post < ActiveRecord::Base
mount_uploader :attachment, AttachmentUploader
end
new.html.erb:
<%= f.label :attachment %><br>
<%= f.file_field :attachment %>
show.html.erb:
<%= attachment_tag @post.attachment.url, class: "post-show" %>
/uploaders/video_uploader.rb
class VideoUploader < CarrierWave::Uploader::Base
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
posts_controller:
def post_params
params.require(:post).permit(:post_id, :title, :body, :date, :image, :remove_image, :video, :attachment)
end
I expect the output of this to be a display of the file whether it is a pdf, ppt or word document.
EDIT:
<iframe src="@post.attachment.url"></iframe>
This was added to the show.html.erb instead of the attachment tag. I do not receive an error anymore but it displays this: