简体   繁体   English

重命名AXLSX的Rails参数

[英]Rename Rails Params for AXLSX

I am getting a dynamic array of fields from my front end application to determine what contents my workbook will have. 我从前端应用程序获取动态字段字段,以确定我的工作簿将包含哪些内容。 Two of the fields will have the same value, but I want different column headings. 两个字段将具有相同的值,但是我想要不同的列标题。 So I have added this to my method: 因此,我已将此添加到我的方法中:

    fields = params[:fields]
    fields[0].replace('new string')
    sheet.add_row fields
    exportees.each do |event_session_registration|
      row_array = params[:fields].map { |field| event_session_registration.try(field) }
      row_array.map! { |value| value == true ? 'Yes' : value }
      row_array.map! { |value| value == false ? 'No' : value }
      sheet.add_row row_array
    end

Fields[0] being the first of the two identical strings. Fields[0]是两个相同字符串中的第一个。

The problem now is that inside of my .each loop, params[:fields] now has the same contents as my updated fields variable. 现在的问题是,在我的.each循环中, params[:fields]现在具有与更新的fields变量相同的内容。 I have tried using .dup but that didn't leave my params unaltered either. 我尝试使用.dup但这也没有使我的参数保持不变。 I am able to get around this problem by doing the following: 通过执行以下操作,我可以解决此问题:

    fields = params[:fields]
    fields[0].replace('new string')
    sheet.add_row fields
    fields[0].replace('original string')

However, I'm curious if there is a cleaner way to duplicate my params for the sake of printing different column headers. 但是,我很好奇是否有一种更干净的方法来复制我的参数,以便打印不同的列标题。 Thanks in advance! 提前致谢!

Try this: 尝试这个:

parameters = params.to_h
fields = parameters[:fields]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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