Generating a PDF with Prawn and Ruby On Rails -


i've been following ryan bate's railscast tutorial (excellent always) have run issue cannot seem resolve.

i have prawn::document rendering using static content fine, ie with

class printpdf < prawn::document   def initialize     super     text "text"   end end 

and in controller

def print   @vegetaux = vegetable.all    respond_to |format|     format.html     format.pdf       pdf = printpdf.new       send_data pdf.render, filename: "vegetaux.pdf", type: "application/pdf", disposition: "inline"     end   end end 

but when try pass in rails model adding this

pdf = printpdf.new(@vegetaux) 

& in pdf object

class printpdf < prawn::document   def initialize(vegetaux)     super     @vegetaux = vegetaux     text "text"   end end 

i error message

no implicit conversion of symbol integer relating line...

pdf = printpdf.new(@vegetaux) 

the object @vegetaux seems ok though, because in html reponse can loop through individual items , display contents, ie /print (html) works fine

<ul> <% @vegetaux.each |vegetable| %>   <li><%= vegetable.nom_commun %></li> <% end %> </ul> 

can explain why i'm getting error when try create pdf document?

thanks!

if inspect @vegetaux object @vegetaux.inspect returns (test data)

#<activerecord::relation [#<vegetable id: 6, nom_commun: "basic flower", famille_id: 1, classe: "something else", genre: "genre", espece: "espece", origine_geographique: "earth", cycle_biologique: "normal", racine: "something else", tige: "another thing", feuillage: "whatevs", fleur: "big skdfhkjs dhfksdhfkj hsdkjfh ksjd hfkjsdh fkjhs...", fruit: "none", graine: "something siomething", modes_de_multiplication_possibles: "lots of things", systemes_de_production_adaptes: "all kinds of things", mise_en_place_de_la_culture: "don't understand question", calendrier_cultural: "may - july", entretien_de_la_culture: "nope", exigences_edaphiques_ideales: "whatevs", irrigation: "keep wet", fertilisation: "keep fertilised", problemes_phytosanitaires_et_protections_adaptees: "none", importance_economique: "very", utilisation: "eat it", diversification: "whatevs", created_at: "2014-11-10 11:37:17", updated_at: "2014-11-19 15:28:08", photo_file_name: "flower.jpg", photo_content_type: "image/jpeg", photo_file_size: 1083468, photo_updated_at: "2014-11-10 11:37:16", exigences_climatiques: "warm & sunny">, #<vegetable id: 13, nom_commun: "qsd", famille_id: 1, classe: "dsf", genre: "sdf", espece: "sdf", origine_geographique: "", cycle_biologique: "", racine: "", tige: "", feuillage: "", fleur: "", fruit: "", graine: "", modes_de_multiplication_possibles: "", systemes_de_production_adaptes: "", mise_en_place_de_la_culture: "", calendrier_cultural: "", entretien_de_la_culture: "", exigences_edaphiques_ideales: "", irrigation: "", fertilisation: "", problemes_phytosanitaires_et_protections_adaptees: "", importance_economique: "", utilisation: "", diversification: "", created_at: "2014-11-19 14:34:18", updated_at: "2014-11-19 14:34:18", photo_file_name: nil, photo_content_type: nil, photo_file_size: nil, photo_updated_at: nil, exigences_climatiques: "">, #<vegetable id: 9, nom_commun: "wxc", famille_id: 1, classe: "wxc", genre: "wxc", espece: "wxc", origine_geographique: "", cycle_biologique: "", racine: "", tige: "", feuillage: "", fleur: "", fruit: "", graine: "", modes_de_multiplication_possibles: "", systemes_de_production_adaptes: "", mise_en_place_de_la_culture: "", calendrier_cultural: "", entretien_de_la_culture: "", exigences_edaphiques_ideales: "", irrigation: "", fertilisation: "", problemes_phytosanitaires_et_protections_adaptees: "", importance_economique: "", utilisation: "", diversification: "", created_at: "2014-11-19 14:19:03", updated_at: "2014-11-19 14:19:03", photo_file_name: nil, photo_content_type: nil, photo_file_size: nil, photo_updated_at: nil, exigences_climatiques: "">, #<vegetable id: 14, nom_commun: "rty", famille_id: 2, classe: "sd", genre: "qsd", espece: "qsdqs", origine_geographique: "", cycle_biologique: "", racine: "", tige: "", feuillage: "", fleur: "", fruit: "", graine: "", modes_de_multiplication_possibles: "", systemes_de_production_adaptes: "", mise_en_place_de_la_culture: "", calendrier_cultural: "", entretien_de_la_culture: "", exigences_edaphiques_ideales: "", irrigation: "", fertilisation: "", problemes_phytosanitaires_et_protections_adaptees: "", importance_economique: "", utilisation: "", diversification: "", created_at: "2014-11-19 17:59:10", updated_at: "2015-04-11 08:50:24", photo_file_name: nil, photo_content_type: nil, photo_file_size: nil, photo_updated_at: nil, exigences_climatiques: "">]>

when override parent's initialize method, calling super no arguments implicitly passes all arguments, since prawn::document's initialize takes options hash (which different passed), trying extract keys vegeteaux.

call super passing in arguments parent class expects, or add parenthesis make obvious aren't passing anything:

class printpdf < prawn::document   def initialize(vegetaux)     super() # added parentheses here call prawn::document.new() no args     @vegetaux = vegetaux     text "text"   end end 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -