Helper method problem

In my main controller have:

def index
@albums=Album.find(:all)
@cart=find_cart
end

since find_cart is also used by another controller, I decided to move
it from to the application_helper.rb file too reduce redundancy.
Rails is throwing an error saying that there is no method find_cart.
Any insight?

On 2008-09-27 04:41, Jon wrote:

Any insight?
You’ll want to put the shared method in app/controllers/application.rb
instead. application_helper.rb is for shared code you use in views, not
controllers.


Greg D.
http://destiney.com/

You’ll want to put the shared method in app/controllers/application.rb

Unless find_cart is used only in the one controller, then you just need
to turn it into a before_filter:

class MainController < ApplicationController
before_filter :set_cart

def index
end

def what_ever
end

private

def set_cart
   @cart = find_cart
end

end

Peace.

class InventoryController < ApplicationController

def index
@albums=Album.find(:all)
@cart=find_cart
end

def add_to_cart
itemType=params[:itemType]
productId=(params[:id]) #parameter passed in from “add to
cart” submission, it’s either 1 or 2 in this case

           if itemType=='album'
                product_temp=Album.find(productId)
                dest='/inventory'
            end
            if itemType=='dvd'
                product_temp=Dvd.find(productId)
                dest='/inventory/dvd'
            end

product=Product.new(itemType,product_temp.title,product_temp.price)
@cart=find_cart
@cart.add_product(product) #add the album to the cart
in
the sessions
redirect_to dest
end

def check_out
@cart=find_cart
redirect_to ‘/inventory/checkOut’
end

def review
@cart=find_cart #for shopping car display in the sidebar
@title=(params[:title])
@itemType=(params[:itemType])

  if @itemType=='album' #must be a better way to reduce the amount 

of
redundant code
@album=Album.find_by_title(@title)
@review=Review.new
@[email protected] #Review.find(:all, :conditions =>
[“album
= ?”, @title])
end
if @itemType==‘dvd’
@dvd=Dvd.find_by_title(@title)
@review=Review.new
@[email protected] #Review.find(:all, :conditions =>
[“album =
?”, @title])
end
end

def dvd
@cart=find_cart
@dvds=Dvd.find(:all)
end

end

The method is “check_out”…i had it in my application.rb file
originally,
tried it in this one and still no change…

On Sat, Sep 27, 2008 at 8:23 PM, Phillip K. <