Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]Bug fix for Heroku breaking when creating pdf with images #48

Open
wants to merge 7 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions app/assets/javascripts/channels/web_notification_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ App.notifications = App.cable.subscriptions.create({

disconnected() {
// Called when the subscription has been terminated by the server
// Display the connection has been lost message
this.container().innerHTML = '<p>Disconneced from server</p>'
setTimeout(() => {
this.container().innerHTML = '';
}, 3000);
console.log('Disconneced');
},

Expand Down
1 change: 1 addition & 0 deletions app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def index

def show
@collection = current_user.collection
#@collection.recipes.with_preloaded_image
begin
PdfGeneratorService.new(@collection).generate_pdf
message ='Your Recipe book has been created'
Expand Down
2 changes: 2 additions & 0 deletions app/models/recipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Recipe < ApplicationRecord
belongs_to :category
has_many :ratings

scope :with_preloaded_image, -> { preload(image_attachment: :blob) }

update_index('recipes') { self }

after_create :notify
Expand Down
11 changes: 7 additions & 4 deletions app/services/pdf_generator_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,26 @@ def create_and_configure_pdf
end

def front_page(pdf)
logo = "#{Rails.root}/app/assets/images/foodhublogo.png"
logo = "#{Rails.root}/app/assets/images/foodhub-logo.png"
pdf.move_down 100
pdf.image logo, position: :center, width: 450, height: 150
pdf.image logo, position: :center, width: 200
pdf.move_down 100
pdf.text 'My Recipe Book', size: 48, align: :center
pdf.move_down 150
pdf.text "by: #{ @collection.user.full_name}", size: 25, align: :right
pdf.move_down 10
pdf.text 'With Recipes from FoodHub', size: 18, align: :right
pdf.text 'With recipes from FoodHub', size: 18, align: :right
end

def add_attachment(filename)
@collection.pdf.attach(io: File.open(Rails.root.join(filename)), filename: filename)
end

def insert_image(pdf, recipe)
pdf.image open(recipe.image.service_url), width: 300, height: 250, position: :center
image_url = recipe.image.attachment.blob.service_url(expires_in: 1.hour)
#image_url = Rails.application.routes.url_helpers.rails_service_blob_url(recipe.image)
pdf.move_down 10
pdf.image open(image_url), width: 500, position: :center if image_url
pdf.move_down 15
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/collections/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
}

if ( isPdfGenerated === true) {
setVisibilityOfViewPdfLink("#{rails_blob_url(@collection.pdf) if @collection.pdf.attached?}");
setVisibilityOfViewPdfLink("#{rails_blob_url(@collection.pdf, disposition: "attachment") if @collection.pdf.attached?}");
}

generateLink.addEventListener('ajax:success', event => {
Expand Down
2 changes: 1 addition & 1 deletion config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mcBgmrthdyS3CpNPVFH7T5y4nPZDhTzbFSVom+tOU725XVrQhxbR7Pu8V9rYo80vcY7NUUlNlYCFnF8b+pYImbD/KAZ57PwBoUz37TsSfffCmQXBYs4MUsmFgh1MTzAL8KZktT7tMsAPkzf3mlxontNFz881umah9oV78LqHedlAKFrSRardhgv5T6BQQXD/6V0HKGe6zU9eBwtldrt/B7YeVwfjfKBPjv66rswbGS5UhMn6f/oA/1NYbZH0RDaQzooY77xjwZefX0gNJH1PxuEcE3svwk8ui5S7O1ILLX2euWMKEJCvG/RlboHGFXSM77wac0gIvkzlQaAvI7lN8s6+LOOKHhUG5nm+NWj6CPy/pnnUZNXN9yYBfj4bQdETAQhFjzOEG5l8kysYTW5rWJHyDuq5deqQqcUumBprN8AiWo2/akBJgqG6WgfqBbt8dZvyEYeRF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