Ruby on Rails CSV putting "" instead of actual quotes -


i attempting generate csv file. fine except blank fields, i'm not quite sure have "" instead of actual quotes. i've provided code i'm using generate file , output.

<% headers = ["username", "name", "e-mail", "phone number"] %> <%= csv.generate_line headers %>  <% @users_before_paginate.each |user| %>   <% row = [ "#{user.username}".html_safe ] %>   <% row << "#{user.profile.first_name} #{user.profile.last_name}".html_safe unless user.profile.blank? %>   <% row << "#{user.email}".html_safe unless user.profile.nil? %>   <% row << "#{user.profile.phone}".html_safe unless user.profile.nil? %>   <%= csv.generate_line row %> <% end %> 

output

username,name,e-mail,phone number    admin,localshopper ,shoplocally1@gmail.com,&quot;&quot;   brian,oliveri design ,brian@oliveridesign.com,727-537-9617   localshopperjenn,jennifer m gentile ,localshopperjenn@hotmail.com,&quot;&quot; 

instead of calling html_safe on each part of array , making new (non-html-safe) string it, try calling @ end, after string returned generate_line:

<%= csv.generate_line(row).html_safe %> 

update: security, need sure template not being sent browser html, raw text/csv file. if row content contains actual html tags <script>, these not escaped, because you've declared output "safe".

if content needs output within html page, you'd better consider correct escaping instead of bypassing this.

consider if need html.erb template generating csv.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -