Hi,
I am developing a web app and am following the text-Agile web development…
Each time I click my “add to cart” button" i always get the page below:I have double checked to see if i have errors in my code,there was none,please what do i need to do to proceed?
NameError in InteractController#add_to_cart
undefined local variable or method `find_cart' for #<InteractController:0x1042d0780>
Hi,
I am developing a web app and am following the text-Agile
web development…
Each time I click my “add to cart” button" i always get
the page below:I have double checked to see if i have errors in my
code,there was none,please what do i need to do to proceed?
NameError in InteractController#add_to_cart
undefined local variable or method `find_cart' for #<InteractController:0x1042d0780>
Hello,
Thanks for your time.my bad! i never figured that out.Can you help out with the find_cart method.Will greatly appreciate
Regards and Respects,
Kindness in thought leads to wisdom.
Kindness in speech leads to eloquence.
Kindness in action leads to love.
Hello,
Thanks for your time.my bad! i never figured that out.Can you help out with the find_cart method.Will greatly appreciate
Did you see the comment on top posting in my previous post?
It is always worth looking carefully at error messages as sometimes
they contain useful information. Yours said "undefined local variable
or method `find_cart'" which could have given you a clue to the
problem.
I am afraid I cannot help out with it as I have no idea what your
application is supposed to do. Presumably you can find something
about it in the tutorial you are following.
For beginners I always recommend working through the Rails Guides,
particularly the one on Getting Started. See
Hello,
thank you for your time.I am actually developing an e commerce website for selling books online.the find_cart method is mean to find the cart displayed at the front end-for the users buying stuffs.Your help wil be appreciated,am just 2 weeks old in RoR
Regards and Respects,
Kindness in thought leads to wisdom.
Kindness in speech leads to eloquence.
Kindness in action leads to love.
Hello,
thank you for your time.I am actually developing an e
commerce website for selling books online.the find_cart method is mean
to find the cart displayed at the front end-for the users buying
stuffs.Your help wil be appreciated,am just 2 weeks old in RoR
Regards and Respects,
In the sample application used in ‘Agile Web Development with Rails’
they define a Cart class (which is not derived from
ActiveRecord::Base). In their StoreController class they define a
find_cart method as:
def find_cart
@cart = (session[:cart] ||= Cart.new)
end
Whether this has any applicability to your case is impossible to know
without knowing a lot more about your application.
i am actually following the book because am doing EXACTLY the same thing.this is my code, have a look at time .will appreciate corrections.i am sick of seeing the error message.
class InteractController < ApplicationController
def index
@products = Product.find_products_for_sale
end
def add_to_cart
product = Product.find(params[:id])
@cart = find_cart
@cart.add_product(product)
rescue ActiveRecord::RecordNotFound
logger.error(“Attempt to access invalid product #{params[:id]}”)
flash[:notice] = “Invalid product”
redirect_to :action => ‘index’
end
def empty_cart
session[:cart] = nil
flash[:notice] = " Now,your cart is currently empty"
redirect_to :action => ‘index’
end
private
def redirect_to_index(msg)
flash[:notice] = msg
redirect_to :action => ‘index’
end
end Regards and Respects,
Kindness in thought leads to wisdom.
Kindness in speech leads to eloquence.
Kindness in action leads to love.
There is no point repeatedly posting the same code. As has been
pointed out several times the problem is that you are missing the
find_cart method. In Agile Development With Rails this is in the
StoreController, as has also been pointed out to you previously. I
suggest you go back to the book and have another look. I believe you
can even download the application source if you wish.
Hello,
when i added the find-cart method(private access) that the controller is loking for, am now getting this syntax error message.Ithis is my method:
private
def find_cart
session[:cart] ||= Cart.new
end
SyntaxError in InteractController#add_to_cart
The error is in your model/cart.rb around line 19 as the error message
indicates. Read the error messages closely and you will find a lot of
information. The error indicates that you have a syntax error in
model/cart.rb. Maybe a block opened without an end or quotes not
matching or parentheses not matching etc.
Hello,
thank you.Ut worked wonders!
Regards and Respects,
Kindness in thought leads to wisdom.
Kindness in speech leads to eloquence.
Kindness in action leads to love.