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.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Waiting for your valuable reply..
--
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
-~----------~----~----~----~------~----~------~--~---
change session(:cart).nil? to session[:cart].nil? session is not a method call On Feb 18, 12:30 pm, Sony Sebastian <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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. > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 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 > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > Waiting for your valuable reply.. > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 18, 5:44 pm, jemminger <jemmin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> change > session(:cart).nil? > > to > session[:cart].nil? > > session is not a method callIf we''re picking nits it is :-) - you just don''t pass any arguments to it. Fred --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Sebastian <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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. > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 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 > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > Waiting for your valuable reply.. > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---