I have a class included in a plugin which contains the following line
user.rb
class My::User < My::AbstractModel
delegate :message_t, :to => ApplicationHelper
#omited
end
So I need to call in this model the *’message_t’* function defined in the application_helper.rb,
However, Jenkins fails testing it giving the error ‘uninitialized constant My::User::ApplicationHelper’ so I suppose the user model is loaded before the application_helper.rb. How can I fix it? Is there an other way to call *’message_t’* or could I change the files loading order and should I?
You can’t access the rails helpers from the model layer. Helpers are designed to assist in presentation and are used by the view (and sometimes controller) layer.
Also,
delegateis meant to be used to transfer messages to directly associated models – not to an arbitrary class.I would recommend moving the
message_tmethod out of ApplicationHelper into some library file that your model can require. Then use a proxy object to call it instead of usingdelegate. Or you can associate a proxy object for this purpose and usedelegateif you like the sound of it 🙂