Accessing a class in Model from Controller

I have a model with Class Cart, but when I try to Cart.new in my controller, it does not recognize the constant Cart. Suggestions??

Hi --

I have a model with Class Cart, but when I try to Cart.new in my controller, it does not recognize the constant Cart. Suggestions??

Please don't keep asking the same question, especially multiple times per day.

When you refer to Cart in the controller, Rails will look in its load path for a file called cart.rb, and if it finds one, it will load it, on the expectation that Cart will be defined there. Are you sure your model file is called cart.rb, and that it's in the app/models directory?

David

David A. Black wrote:

Hi --

I have a model with Class Cart, but when I try to Cart.new in my controller, it does not recognize the constant Cart. Suggestions??

Please don't keep asking the same question, especially multiple times per day.

Sorry for the duplicate post. Thought maybe a more descriptive title would yield results.

I did manage to figure the problem out earlier, and it was the file name. I'm unfamiliar with the rails conventions, as I am still learning.

Thanks

Hi --

David A. Black wrote:

Hi --

I have a model with Class Cart, but when I try to Cart.new in my controller, it does not recognize the constant Cart. Suggestions??

Please don't keep asking the same question, especially multiple times per day.

Sorry for the duplicate post. Thought maybe a more descriptive title would yield results.

I did manage to figure the problem out earlier, and it was the file name. I'm unfamiliar with the rails conventions, as I am still learning.

For most setup and housekeeping tasks, Rails helps you with either rake tasks or admin scripts. To create a model, you would do this, from the top directory of your application:

   ruby ./script/generate model cart

and the correctly-named file will be created for you. It's good to understand why things do or do not work, but it's also good to let Rails do these automated tasks, since it does them consistently and quickly.

David