Is there a method I can use across controllers and if so, how do I use it?
Posted
by Angela
on Stack Overflow
See other posts from Stack Overflow
or by Angela
Published on 2010-06-17T00:45:07Z
Indexed on
2010/06/17
0:52 UTC
Read the original article
Hit count: 247
I have several controllers that take an instance of different classes each (Email, Call, Letter, etc) and they all have to go through this same substitution:
@email.message.gsub!("{FirstName}", @contact.first_name)
@email.message.gsub!("{Company}", @contact.company_name)
@email.message.gsub!("{Colleagues}", @colleagues.to_sentence)
@email.message.gsub!("{NextWeek}", (Date.today + 7.days).strftime("%A, %B %d"))
@email.message.gsub!("{ContactTitle}", @contact.title )
So, for example, @call.message for Call, @letter.message for Letter, etcetera.
This isn't very dry. I'd like to have something like
def messagesub(asset)
@asset.message.gsub....
end
or something like that so I can just use messagesub method in each controller.
© Stack Overflow or respective owner