Reputation: 47
I'm trying to parse some text and link certain strings that come from various models and is headed to a couple of different views. I though application_helper.rb was the right place to put this. (Still a rookie at figuring out where best to code things).
application_helper.rb
def link_buffs(text)
Buff.all.each do |b|
text = text.gsub('[' + b.name + ']',link_to('[' + b.name + ']', b, class: b.name + '-buff buff')).to_s
end
return text
end
sample buff data
buff.id:integer
buff.name = 'Poison'
sample text Places a 5% [Poison] debuff
And in the views, I'm calling link_buffs(string).html_safe
in a few different places. But it appears to be silently failing and all I can figure out right now is that link_to isn't available in the helper.
So the question is how do I make link_to available in the helper or should I be putting this code somewhere else?
Upvotes: 1
Views: 205
Reputation: 6952
You should be able to do:
ActionController::Base.helpers.link_to()
There are other answers to this question: create a link_to in controller
Upvotes: 1