# FasterCSV

**URL:** <https://www.ruby-forum.com/t/fastercsv/172819>\
**Category:** Rails\
**Created:** [July 28, 2009, 4:08pm UTC](https://www.ruby-forum.com/t/fastercsv/172819 "2009-07-28T16:08:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [July 28, 2009, 4:08pm UTC](https://www.ruby-forum.com/t/fastercsv/172819/1 "2009-07-28T16:08:59Z")

</div>

have problem with getting output. I get an error no matter how I try to  
get output…

NoMethodError in Reports#commissions\_export

Showing app/views/reports/commissions\_export.erb where line #26 raised:

undefined method `send\_data’ for #ActionView::Base:0xb717a2c0

This is all I have in commissions\_export.erb

\<%= csv\_string = FasterCSV.generate do |csv|  
csv \<\< [‘Commission Report’]  
csv \<\< [ ‘Reporting Period Starts’, ‘’, ‘’, ‘’,  
@period.lastdate\_in\_period.strftime("%m-%d-%Y") ]  
csv \<\< []  
csv \<\< [ “Customer (Branch)”,  
“Invoice #”,  
“Stock ID”,  
“Qty.”,  
“Sale Price”,  
“Cost”,  
“Gross Profit”,  
“Commission”  
]  
@sales.each do |sale|  
csv \<\< [ sale.custbranch,  
sale.transno,  
sale.stockid,  
sale.qty,  
sale.amt.to\_fl(2),  
sale.cost.to\_fl(2),  
(sale.amt - sale.cost).to\_fl(2),  
((sale.amt - sale.cost) \* @salesman.commissionrate1).to\_fl(2)  
]  
end  
end  
send\_data csv\_string, :type =\> “text/plain”,  
:filename=\>@salesman.salesmanname + “\_Commissions.csv”,  
:disposition =\> ‘attachment’  
%\>

(send\_data stuff is from examples which don’t seem to work)

–  
This message has been scanned for viruses and  
dangerous content by MailScanner, and is  
believed to be clean.

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [July 28, 2009, 4:22pm UTC](https://www.ruby-forum.com/t/fastercsv/172819/2 "2009-07-28T16:22:27Z")

</div>

On Tue, Jul 28, 2009 at 10:07 AM, Craig W.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> This is all I have in commissions\_export.erb  
> “Sale Price”,  
> sale.cost.to\_fl(2),  
> (send\_data stuff is from examples which don’t seem to work)
> 
> –  
> This message has been scanned for viruses and  
> dangerous content by MailScanner, and is  
> believed to be clean.
> 
> >

Craig,

I am using the format below for a .csv export:

send\_data(csv,  
:type =\> ‘text/csv; charset=utf-8; header=present’,  
:filename =\> filename)

A variation of the above may help.

I remember banging my head against the wall trying to get this to  
work…

Casey

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [July 28, 2009, 4:40pm UTC](https://www.ruby-forum.com/t/fastercsv/172819/3 "2009-07-28T16:40:36Z")

</div>

On Tue, 2009-07-28 at 10:21 -0400, Casey Ellett wrote:

> ```
> csv << [ 'Reporting Period Starts', '', '', '',
> ]
> ]
> --
> 
> ```
> 
> send\_data(csv,  
> :type =\> ‘text/csv; charset=utf-8; header=present’,  
> :filename =\> filename)
> 
> A variation of the above may help.
> 
> I remember banging my head against the wall trying to get this to  
> work…

* * *

I still get the same error…do you think that this is caused because  
this is code inside a view? If I put this code in my controller, then I  
get an error because it wants a view file, even if I add  
‘render :layout =\> false’

this makes me crazy because I had all of this kind of stuff working in  
1.2.x and now have to resort to other things in 2.3.2 and dealing with  
all sorts of new errors.

Thanks

Craig

–  
This message has been scanned for viruses and  
dangerous content by MailScanner, and is  
believed to be clean.

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [July 28, 2009, 5:05pm UTC](https://www.ruby-forum.com/t/fastercsv/172819/4 "2009-07-28T17:05:12Z")

</div>

On Tue, 2009-07-28 at 07:39 -0700, Craig W. wrote:

> > ```
> > NoMethodError in Reports#commissions_export
> > csv << ['Commission Report']
> > "Commission"
> > @salesman.commissionrate1).to_fl(2)
> > 
> > ```
> > 
> > I am using the format below for a .csv export:  
> > I still get the same error…do you think that this is caused because  
> > this is code inside a view? If I put this code in my controller, then I  
> > get an error because it wants a view file, even if I add  
> > ‘render :layout =\> false’
> 
> this makes me crazy because I had all of this kind of stuff working in  
> 1.2.x and now have to resort to other things in 2.3.2 and dealing with  
> all sorts of new errors.

* * *

that was it…I had to move it all back into the controller and et  
voila…

Thanks - by the way, I found this to be more useful…  
:type =\> ‘application/vnd.ms-excel; charset=utf-8;  
header=present’,

Craig

–  
This message has been scanned for viruses and  
dangerous content by MailScanner, and is  
believed to be clean.
