Alexey
Alexey

Reputation: 2386

Access to methods class in views

I have class that generate some js. Where i should put this class and how call methods from it in views?

class Hits
   @@config = Settings.statistic

   class << self
      def js_counter
         if @@config.enable
            ...
         end
      end
   end  
end

Thank you!

Upvotes: 0

Views: 94

Answers (2)

Valery Kvon
Valery Kvon

Reputation: 4496

Put class to models directory if you want.

In a view:

<%= javascript_tag Hits.js_counter.html_escape $>

# if js_counter returns String

Upvotes: 0

saGii
saGii

Reputation: 477

put it in the lib folder and require it in an initializer.

Upvotes: 1

Related Questions