# NoMethodError... but its not a method!

**URL:** <https://www.ruby-forum.com/t/nomethoderror-but-its-not-a-method/129332>\
**Category:** Rails\
**Created:** [February 16, 2008, 10:51pm UTC](https://www.ruby-forum.com/t/nomethoderror-but-its-not-a-method/129332 "2008-02-16T22:51:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [February 16, 2008, 10:51pm UTC](https://www.ruby-forum.com/t/nomethoderror-but-its-not-a-method/129332/1 "2008-02-16T22:51:22Z")

</div>

Hi everyone,  
I am putting together an application in which each part of it was  
tested individually. Now that it is put together, I’m having problems…  
The one giving me problems is my “ImportController” which parses a CSV  
during post and puts it into my database. I have two separate CSV upload  
actions (one is for a bill called “bes” and the other from the provider  
“prov”). The one for BES works fine. Prov worked perfectly fine before,  
but now it gives me this error:

undefined method `prov\_charges\_tot=’ for #Prov:0x4674734

The thing is, thats not even supposed to be a method! The relevant part  
of the view looks like this:

\<% form\_for :dump, :url =\> { :controller =\> ‘import’, :action =\> ‘bes’  
}, :html =\> { :multipart =\> true } do |f| -%\>  
Select a BES CSV File :  
\<%= f.file\_field :file -%\>  
\<%= submit\_tag ‘Submit’ -%\>  
\<% end -%\>

\<% form\_for :dump, :url =\> { :controller =\> ‘import’, :action =\> ‘prov’  
}, :html =\> { :multipart =\> true } do |f| -%\>  
Select a Provider CSV File :  
\<%= f.file\_field :file -%\>  
\<%= submit\_tag ‘Submit’ -%\>  
\<% end -%\>

Perhaps it is a naming problem? I am not sure. My controller looks like  
this:

def bes  
@currenttime = Time.now  
@parsed\_file = FasterCSV::parse(params[:dump][:file])  
@parsed\_file.shift  
n=0  
@parsed\_file.each do |row|  
c=Bes.new  
c.bes\_id=row[0]  
# There are a bunch more of these lines, but this part works.  
c.bes\_handheldconfigid=row[21]  
@besnumber = Bes.new params[:bes]

if c.save  
n=n+1  
GC.start if n%50==0  
end  
Bes.delete\_all([“created\_at \< ?”, @currenttime])  
flash.now[:message] = ‘CSV BES Import Successful’  
end  
end

def prov  
@currenttime = Time.now  
@parsed\_file = FasterCSV::parse(params[:dump][:file])  
@parsed\_file.shift  
n=0  
@parsed\_file.each do |row|  
c=Prov.new  
c.prov\_info\_fac=row[0]  
c.prov\_info\_bac=row[3]  
c.prov\_info\_cycle\_end\_date=row[5]

c.prov\_service\_name=row[1]  
c.prov\_service\_number=row[2]  
c.prov\_service\_provider=row[4]

c.prov\_charges\_tot=row[43] # THIS IS WHERE THE ERROR OCCURS  
c.prov\_charges\_tot\_access=row[6]  
c.prov\_charges\_tot\_airtime=row[7]  
c.prov\_charges\_tot\_kb=row[8]  
c.prov\_charges\_tot\_messaging=row[9]  
c.prov\_charges\_tot\_features=row[12]  
c.prov\_charges\_tot\_equipment=row[25]  
c.prov\_charges\_tot\_longdistance=row[26]  
c.prov\_charges\_tot\_roaming=row[30]  
c.prov\_charges\_tot\_misc=row[38]  
c.prov\_charges\_tot\_other=row[41]  
c.prov\_charges\_tot\_taxesfees=row[42]

c.prov\_charges\_messaging\_sms=row[10]  
c.prov\_charges\_messaging\_mms=row[12]  
c.prov\_charges\_feat\_basicvoice=row[14]  
c.prov\_charges\_feat\_voicemail=row[15]  
c.prov\_charges\_feat\_wos=row[16]  
c.prov\_charges\_feat\_aod=row[17]  
c.prov\_charges\_feat\_intnl=row[18]  
c.prov\_charges\_feat\_mou=row[19]  
c.prov\_charges\_feat\_data=row[20]  
c.prov\_charges\_feat\_vidshare=row[21]  
c.prov\_charges\_feat\_wifi=row[22]  
c.prov\_charges\_feat\_messaging=row[23]  
c.prov\_charges\_feat\_otherfees=row[24]  
c.prov\_charges\_feat\_otherfeat=row[25]  
c.prov\_charges\_ld\_local=row[28]  
c.prov\_charges\_ld\_intnl=row[29]  
c.prov\_charges\_ld\_directory=row[30]  
c.prov\_charges\_roam\_airtime=row[32]  
c.prov\_charges\_roam\_kb=row[33]  
c.prov\_charges\_roam\_surcharges=row[34]  
c.prov\_charges\_roam\_ld=row[35]  
c.prov\_charges\_roam\_intnl=row[36]  
c.prov\_charges\_roam\_intnl\_ld=row[37]  
c.prov\_charges\_roam\_taxes=row[38]  
c.prov\_charges\_misc\_voice=row[40]  
c.prov\_charges\_misc\_data=row[41]

```
 if c.save
    n=n+1
    GC.start if n%50==0
    end

 Prov.delete_all(["created_at < ?", @currenttime])
 flash.now[:message] = 'CSV Import Successful'

```

end  
end

My models are just empty, so nothing to worry about there. I am really  
having a frustrating time with this one… I think it would be a naming  
thing, but I really don’t know.

Any help is greatly appreciated! Thank you all very much!

- Jeff M.

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [February 16, 2008, 11:22pm UTC](https://www.ruby-forum.com/t/nomethoderror-but-its-not-a-method/129332/2 "2008-02-16T23:22:20Z")

</div>

I got it, I forgot I added that column after I migrated the database…  
thus, there was no prov\_charges\_tot column… stupid me…

Thanks anyway!

- Jeff

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [February 18, 2008, 1:14am UTC](https://www.ruby-forum.com/t/nomethoderror-but-its-not-a-method/129332/3 "2008-02-18T01:14:53Z")

</div>

Jeff,

That’s a lot of very repetitive code in your prov method. You could  
use a hash and really clean that up (and possibly make it easier to  
maintain).

At the top of the method (or maybe as a constant on the Prov class?)  
add something like this:  
prov\_map = {:prov\_info\_fac =\> 0, :prov\_info\_bac  
=\>3, :prov\_info\_cycle\_end\_date=\>5, … }

then your processing loop looks like:

…  
@parsed\_file.each do |row|  
c=Prov.new  
prov\_map.each{|attr, column| c.send “#{att}r=”, row[column] }  
c.save  
end  
…

On Feb 16, 5:22 pm, Jeff M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
