# Really confusing issue involving ActiveRecord and a NoMethodError

**URL:** <https://www.ruby-forum.com/t/really-confusing-issue-involving-activerecord-and-a-nomethoderror/152399>\
**Category:** Rails\
**Created:** [November 3, 2008, 3:44pm UTC](https://www.ruby-forum.com/t/really-confusing-issue-involving-activerecord-and-a-nomethoderror/152399 "2008-11-03T15:44:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cdubd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e19adc/32.png) [@cdubd](https://www.ruby-forum.com/u/cdubd)\
**Post date:** [November 3, 2008, 3:44pm UTC](https://www.ruby-forum.com/t/really-confusing-issue-involving-activerecord-and-a-nomethoderror/152399/1 "2008-11-03T15:44:59Z")

</div>

Hey Everyone,

I have been working on a project where I process an XML file that  
contains data about a music playlist, and I use 3 models: Playlist,  
Artist, and Song. Each model is mapped to a table in my database, and  
when my app processes the XML file, it will populate the database  
accordingly.

The issue I have is that the Artist class and the Song class seem to  
be undefined, even though they absolutely are defined. I can interact  
with the Playlist class just fine, and create new entries in the  
database, but for some reason, when I try and create a new instance of  
the Artist class, or the Song class I get the following error:

undefined method `create’ for UploadController::Artist:Class

I decided to check this out using the Console, and I am able to create  
a new instance of the Artist class, and populate the database in the  
console, so the issue only resides in my web application.

Could I be missing some small piece of trivial information? I was  
under the impression that I could access all of the models from any  
controller I am using, but I can only access a single model at the  
moment.

Any help would be great, this issue is driving me crazy.

Thanks!

---

<div class="post-metadata">

**Author:** ![cdubd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e19adc/32.png) [@cdubd](https://www.ruby-forum.com/u/cdubd)\
**Post date:** [November 3, 2008, 3:51pm UTC](https://www.ruby-forum.com/t/really-confusing-issue-involving-activerecord-and-a-nomethoderror/152399/2 "2008-11-03T15:51:28Z")

</div>

On Nov 3, 2:37 pm, cdubd [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hey Everyone,
> 
> I have been working on a project where I process an XML file that  
> contains data about a music playlist, and I use 3 models: Playlist,  
> Artist, and Song. Each model is mapped to a table in my database, and  
> when my app processes the XML file, it will populate the database  
> accordingly.

What is in your upload controller ?

> The issue I have is that the Artist class and the Song class seem to  
> be undefined, even though they absolutely are defined.

Actually it looks more like they have been defined a second time

Fred  
I can interact

---

<div class="post-metadata">

**Author:** ![cdubd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e19adc/32.png) [@cdubd](https://www.ruby-forum.com/u/cdubd)\
**Post date:** [November 5, 2008, 5:44pm UTC](https://www.ruby-forum.com/t/really-confusing-issue-involving-activerecord-and-a-nomethoderror/152399/3 "2008-11-05T17:44:51Z")

</div>

> What is in your upload controller ?
> 
> > The issue I have is that the Artist class and the Song class seem to  
> > be undefined, even though they absolutely are defined.
> 
> Actually it looks more like they have been defined a second time
> 
> Fred  
> I can interact

The following lines appear in my upload controller:

@playlistObject = Playlist.create(:name =\> n)

Artist.create(:name =\> @artistList[j])

Song.create(:name =\> song.name, :artist\_id =\> artist.id, :minutes =\>  
song.minutes, :seconds =\> song.seconds)

The first line, where I create a new Playlist object works, but the  
other two do not. I can post the entire code listing in the upload  
controller if you think it would help.

-Casen

---

<div class="post-metadata">

**Author:** ![cdubd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e19adc/32.png) [@cdubd](https://www.ruby-forum.com/u/cdubd)\
**Post date:** [November 5, 2008, 6:14pm UTC](https://www.ruby-forum.com/t/really-confusing-issue-involving-activerecord-and-a-nomethoderror/152399/4 "2008-11-05T18:14:16Z")

</div>

On 5 Nov 2008, at 16:43, cdubd wrote:

> The first line, where I create a new Playlist object works, but the  
> other two do not. I can post the entire code listing in the upload  
> controller if you think it would help.

Yes.

Fred

---

<div class="post-metadata">

**Author:** ![cdubd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e19adc/32.png) [@cdubd](https://www.ruby-forum.com/u/cdubd)\
**Post date:** [November 6, 2008, 12:08pm UTC](https://www.ruby-forum.com/t/really-confusing-issue-involving-activerecord-and-a-nomethoderror/152399/5 "2008-11-06T12:08:07Z")

</div>

I discovered the problem! When I was going to cut and paste the code,  
I noticed some classes I defined from within the controller (as a  
test) that I had later forgotten about completely because they were at  
the bottom of a lot of code. And as you have probably guessed the  
class names were Artist, and Song. I have been humbled!

Thanks again,

Casen
