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? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 2008-09-27 04:41, Jon wrote:> 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?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 Donald http://destiney.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 -~----------~----~----~----~------~----~------~--~---
> You''ll want to put the shared method in app/controllers/application.rbUnless 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. -- 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 -~----------~----~----~----~------~----~------~--~---
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 @reviews=@album.reviews #Review.find(:all, :conditions => ["album = ?", @title]) end if @itemType==''dvd'' @dvd=Dvd.find_by_title(@title) @review=Review.new @reviews=@dvd.reviews #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 Koebbe < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > 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. > -- > 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 -~----------~----~----~----~------~----~------~--~---