简体   繁体   中英

Rails issue with params hash

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM