Reputation: 3
I need to export a previously rendered table from my view to pdf. When I build the array of hashes as follows:
__index = 0
@people.each do |p| %>
@pdfdata[__index] = {
[:name] => p.name.to_s,
[:surname] => p.surname.to_s
__index += 1
end
end
and send it to the controller in order to export it on a pdf as follows:
hidden_field_tag(:pdfdata, @pdfdata)
when I get the params[:pdfdata]
I cannot find a way unless I build a string parser to map the data accordingly... is there a better way to do this?
Upvotes: 0
Views: 144
Reputation: 1001
Modifying your code a little bit to get
@people.each_with_index do |p,i| %>
@pdfdata[i] = {
[:name] => p.name.to_s,
[:surname] => p.surname.to_s}
end
and use this gem to create the hidden has field
https://github.com/brianhempel/hash_to_hidden_fields
Upvotes: 1