How to Store Shrimp PDF Files in Amazon S3

I have a problem with the outline. In my model, I have the following setting:

class Pdffiles < ActiveRecord::Base
  belongs_to :user

  has_attached_file :invoice_file,
                    :path => ":rails_root/public/pdffiles/:user_id/:style/:basename.:extension",
                    :url => "/pdffiles/:user_id/:style/:basename.:extension",

                    :storage => :s3,
                        :bucket => '...',
                        :s3_credentials => {
                          :access_key_id => '...',
                          :secret_access_key => '...'
                        }  
end

and in the controller my action looks like:

   pdf = Prawn::Document.new
    pdf.move_down 70

    pdf.text("Prawn Rocks")
    pdf.render_file('prawn.pdf')
    pdf_file = File.open('prawn.pdf')

    pdff = Pdffile.new()
    pdff.pdffile_file = pdf_file
    pdff.user_id = todays_user.id
    pdff.save

And my problem is that this PDF file is stored on the S3 server, but in a bad place. Instead, a directory app/public/pdff/id_of_a_user/file_name_of_pdf_fileis a file saved in

Users/my_name/my_ruby_root_directory/name_of_my_project/public/pdffiles/id_of_a_user/file_name_of_pdf_file.

I'm not quite sure if I use shrimp correctly to save PDF files, but I think that the problem may be in the controller, where I created the place where the created file should be saved ...

I would like to ask you what I need to change to save the PDF files to the correct directory in S3 ... All the tips will be appreciated!

Manny, thanks, Sep.

+5
2

Users/my_name/my_ruby_root_directory/name_of_my_project/public :rails_root/public , . , , s3- app/public/pdff/id_of_a_user/file_name_of_pdf_file, paperclip : app/public/pdffiles/:user_id/:style/:basename.:extension

, , pdff.invoice_file = pdf_file pdff.pdffile_file = pdf_file

, .

+1

All Articles