pdf_content = *Content you want to save in the file* File.open(Rails.root.join('public', 'user_details', filename), 'wb') do |file| file.write(pdf_content.read) end