That means that @cart is nil. The error messages in rails are not
always perfectly clear but usually careful consideration of the
message will yield clues as to the problem.
despite i have this code in my model called Card
Cart Model:
class Cart < ActiveRecord::Base
[snip]
end
end
it is unable to identify it
what is the problem
As I said at the top the problem is that @cart is nil, it is probably
not a problem in the model itself, but in the controller. Have a look
at the Rails Guide on debugging which will provide techniques you can
use to debug the code and work out why it is nil.
Putting aside the fact that you didn’t give enough information about to
diagnose the problem, I’ll only answer because it’s obvious.
The answer to your question lies in the origins of the @cart instance
variable. It’s not defined automagically; you should define it in the
controller, and you are most likely forgetting to do it.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.