Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call methods defined in ApplicationController in models

I have defined method in ApplicationController

class ApplicationController < ActionController::Base
   helper_method :get_active_gateway
   def get_active_gateway(cart)
     cart.account.gateways
   end
end

When I am calling this method in model

class Order < ActiveRecord::Base
   def transfer
     active= get_active_gateway(self.cart)
   end
end

It throwing error undefined local variable get_active_gateway.

So I wrote

class Order < ActiveRecord::Base
   def transfer
    active= ApplicationContoller.helpers.get_active_gateway(self.cart)
   end
end

Then it was throwing error undefined method nil for Nilclass.

I am working in Rails 3.2.0.

like image 955
Beena Shetty Avatar asked Apr 17 '12 12:04

Beena Shetty


1 Answers

Why would you need such thing? The model should not know about its controllers. Maybe a redesign of your system will be more appropriate in this case.

Here is a link to similar thread.

like image 114
Boris Strandjev Avatar answered Oct 01 '22 03:10

Boris Strandjev