kris.vandenbergh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Oct-15 12:40 UTC
ArgumentError in StoreController#add_to_cart: wrong number of arguments (1 for 0)
I am really new to Ruby and Rails but as you probably see I am trying
to get the shopping card working from the book. I am getting this
error but I really don''t know what to do. I have looked up several of
topics that stated the same problem but as far as I am, nothing has
helped me out yet. Is there something wrong with the Product model?
This is in the StoreController and I believe it is all good.
def add_to_cart
@cart = find_cart
product = Product.find(params[:id])
@cart.add_product(product)
end
Thanks in advance
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Rick DeNatale
2007-Oct-15 14:20 UTC
Re: ArgumentError in StoreController#add_to_cart: wrong number of arguments (1 for 0)
On 10/15/07, kris.vandenbergh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <kris.vandenbergh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I am really new to Ruby and Rails but as you probably see I am trying > to get the shopping card working from the book. I am getting this > error but I really don''t know what to do. I have looked up several of > topics that stated the same problem but as far as I am, nothing has > helped me out yet. Is there something wrong with the Product model? > > This is in the StoreController and I believe it is all good. > > def add_to_cart > @cart = find_cart > product = Product.find(params[:id]) > @cart.add_product(product) > endWell, let''s see, the title of your post is "ArgumentError in StoreController#add_to_cart, wrong number of arguments (1 for 0)." I assume that this is because that''s the error you are seeing. So what could that mean? It means that someone is calling StoreController#add_to_cart with an argument, but add_to_cart doesn''t accept any arguments. The problem isn''t in the definition of add_to_cart, controller action methods don''t take ruby arguments. So... Somewhere some other code. A view? A model method, some other controller method is calling add_to_cart with a parameter. That''s why the error page should show a stack trace, doesn''t it? That should point you to the code which called add_to_cart which is the code which needs to be fixed. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
kris.vandenbergh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Oct-16 11:47 UTC
Re: ArgumentError in StoreController#add_to_cart: wrong number of arguments (1 for 0)
Hey Rick,
First of all, thank you for your reply, it finally works!
So what did I do?I analyzed the stack trace and concluded that the
problem was situated in the cart.rb
At line 13:
@items << CartItem.new(product)
It could not assign a new product to the CartItem model so I looked at
the cart_item.rb:
The "initialize" - which stands for constructor in Ruby I guess - was
spelled wrong and that was my problem! Now it seems to work properly.
On 15 okt, 16:20, "Rick DeNatale"
<rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> On 10/15/07, kris.vandenbe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
<kris.vandenbe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
>
>
> > I am really new to Ruby and Rails but as you probably see I am trying
> > to get the shopping card working from the book. I am getting this
> > error but I really don''t know what to do. I have looked up
several of
> > topics that stated the same problem but as far as I am, nothing has
> > helped me out yet. Is there something wrong with the Product model?
>
> > This is in the StoreController and I believe it is all good.
>
> > def add_to_cart
> > @cart = find_cart
> > product = Product.find(params[:id])
> > @cart.add_product(product)
> > end
>
> Well, let''s see, the title of your post is "ArgumentError in
> StoreController#add_to_cart, wrong number of arguments (1 for 0)." I
> assume that this is because that''s the error you are seeing.
>
> So what could that mean? It means that someone is calling
> StoreController#add_to_cart with an argument, but add_to_cart
doesn''t
> accept any arguments.
>
> The problem isn''t in the definition of add_to_cart, controller
action
> methods don''t take ruby arguments. So...
>
> Somewhere some other code. A view? A model method, some other
> controller method is calling add_to_cart with a parameter.
>
> That''s why the error page should show a stack trace,
doesn''t it? That
> should point you to the code which called add_to_cart which is the
> code which needs to be fixed.
>
> --
> Rick DeNatale
>
> My blog on Rubyhttp://talklikeaduck.denhaven2.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Mihanixroom Qqq
2009-Mar-11 10:09 UTC
Re: ArgumentError in StoreController#add_to_cart: wrong number of arguments (1 for 0)
kris.vandenbergh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> Hey Rick, > > First of all, thank you for your reply, it finally works! > So what did I do?I analyzed the stack trace and concluded that the > problem was situated in the cart.rb > At line 13: > > @items << CartItem.new(product) > > It could not assign a new product to the CartItem model so I looked at > the cart_item.rb: > The "initialize" - which stands for constructor in Ruby I guess - was > spelled wrong and that was my problem! Now it seems to work properly.Ok! And Well! And if this line and listed all above is present, but the error remains? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Chang hoon Chin
2010-Jun-15 09:07 UTC
Re: ArgumentError in StoreController#add_to_cart: wrong number of arguments (1 for 0)
kris.vandenbergh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> I am really new to Ruby and Rails but as you probably see I am trying > to get the shopping card working from the book. I am getting this > error but I really don''t know what to do. I have looked up several of > topics that stated the same problem but as far as I am, nothing has > helped me out yet. Is there something wrong with the Product model? > > This is in the StoreController and I believe it is all good. > > def add_to_cart > @cart = find_cart > product = Product.find(params[:id]) > @cart.add_product(product) > end > > Thanks in advanceedit in cart_item.rb // before def initialize @product = product @quantity = 1 end // after def initialize(product) @product = product @quantity = 1 end -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.