# Wrong number of arguments (1 for 0)

**URL:** <https://www.ruby-forum.com/t/wrong-number-of-arguments-1-for-0/160674>\
**Category:** Rails\
**Created:** [February 18, 2009, 6:30pm UTC](https://www.ruby-forum.com/t/wrong-number-of-arguments-1-for-0/160674 "2009-02-18T18:30:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zonyzeb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/48db29/32.png) [@zonyzeb](https://www.ruby-forum.com/u/zonyzeb)\
**Post date:** [February 18, 2009, 6:30pm UTC](https://www.ruby-forum.com/t/wrong-number-of-arguments-1-for-0/160674/1 "2009-02-18T18:30:00Z")

</div>

Hello,  
I am new to ruby on rails. When I tried to create a session I am  
getting an error, ‘wrong number of arguments (1 for 0)’, in my  
controller.

```auto
 ArgumentError in CustomerController#add_to_cart

wrong number of arguments (1 for 0)

RAILS_ROOT: /project/bob_shopping
Application Trace | Framework Trace | Full Trace

app/controllers/customer_controller.rb:36:in `session'
app/controllers/customer_controller.rb:36:in `add_to_cart'

```

My controller is …

def add\_to\_cart  
if request.post?  
product\_id = params[:product\_id]  
quantity = params[:quantity]  
account = get\_account()  
error)—\> session[:cart] = SessionCart.new(account) if  
session(:cart).nil?  
session[:cart].add\_product( product\_id)  
if quantity \>= 2 and quantity \<= 50  
for i in 1…quantity-1  
session[:cart].add\_product(product\_id)  
end  
end  
flash[:notice] = ‘Your order has been placed.’  
redirect\_to :action=\>‘index’ and return true  
end  
end

```auto

Waiting for your valuable reply..
```

---

<div class="post-metadata">

**Author:** ![zonyzeb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/48db29/32.png) [@zonyzeb](https://www.ruby-forum.com/u/zonyzeb)\
**Post date:** [February 18, 2009, 6:45pm UTC](https://www.ruby-forum.com/t/wrong-number-of-arguments-1-for-0/160674/2 "2009-02-18T18:45:29Z")

</div>

change  
session(:cart).nil?

to  
session[:cart].nil?

session is not a method call

On Feb 18, 12:30 pm, Sony S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![zonyzeb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/48db29/32.png) [@zonyzeb](https://www.ruby-forum.com/u/zonyzeb)\
**Post date:** [February 18, 2009, 6:52pm UTC](https://www.ruby-forum.com/t/wrong-number-of-arguments-1-for-0/160674/3 "2009-02-18T18:52:03Z")

</div>

On Feb 18, 5:44 pm, jemminger [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> change  
> session(:cart).nil?
> 
> to  
> session[:cart].nil?
> 
> session is not a method call

If we’re picking nits it is 🙂 - you just don’t pass any arguments to  
it.

Fred

---

<div class="post-metadata">

**Author:** ![zonyzeb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/48db29/32.png) [@zonyzeb](https://www.ruby-forum.com/u/zonyzeb)\
**Post date:** [February 18, 2009, 6:52pm UTC](https://www.ruby-forum.com/t/wrong-number-of-arguments-1-for-0/160674/4 "2009-02-18T18:52:39Z")

</div>

It would be helpful to see the CustomerController code for the new  
method, but…

I have to assume that new should be called as:

session[:cart] = SessionCart.new() if session(:cart).nil?

On Feb 18, 7:30 am, Sony S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
