Access to application.rb methods

Why can’t I access the utility methods defined in applicaion.rb from the
model classes? If that does not work, where is the best place to put
common utility methods that must be available to all the models.

thanks

If you want some more instance methods on all your models, just add
them to ActiveRecord::Base in environment.rb

class ActiveRecord::Base
def my_method
“hello”
end
end

Then your models behave like…

class Person < ActiveRecord::Base
end

Person.new.my_method # => hello

-Jonathan.

…or add them to a module which you include in the model.
application.rb is a controller (indeed the ApplicationController from
which the other controllers inherit methods, filters etc), and therefore
methods and filters defined in it shouldn’t be accessible to the models.
MVC and all that…
HTH

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs