session - How can i call the method from one controller in another controller in rails 3.2? -


i have been searching net last few hours cannot find how call 1 of method in controller have created in controller used populate html page in view.

the method trying call one:

class cataloguescontroller < applicationcontroller     def index     @catalogues = catalogue.all      respond_to |format|       format.html # index.html.erb       format.json { render json: @catalogues }     end 

and trying call in following method:

      def index     session[:cart].catalogues = catalogue.all   end 

rails in not having , returning following error when run in html page.

undefined method `catalogues=' {:id=>5}:hash 

any appreciated...

edit

cart_controller

class cartcontroller < applicationcontroller    before_filter     session[:cart] = session[:cart] || {} # set empty cart if no cart exist   end      def index     session[:cart].catalogues = catalogue.all   end    def success   end     def add     id = params[:id]     amount = session[:cart][id] || 0 # gets cart amount or 0 if no amount found     session[:cart][id] = amount + 1 # set new amount     @catalogue = catalogue.find(params[:id])     session[:cart]  = {:id => @catalogue.id }     redirect_to action: "index"      # @catalogue = catalogue.find(params[:id])     # session[:cart] = cart     # cart = {:id => @catalogue.id, :catalogue => @catalogue.name,category => @catalogue.category, :code => @catalogue.code , :colour=> @catalogue.colour, :description => @catalogue.description, :image  => @catalogue.image , :unitprice => @catalogue.unitprice, :unitquantity => @catalogue.unitquantity, :unitweight => @catalogue.unitweight }     # session[:cart] = cart     # render 'cart/add'   end    def remove     end    def clear   end    def checkout    end  end 


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -