I have a rails helper using the structore below, but when I use it I get the message
undefined method 'link_to'
The helper is arranged as:
module MyHelper
class Facet
def render_for_search
link_to("Value", params)
end
end
class FacetList
attr_accessor :facets
def initialize
#Create facets
end
def render_for_search
result = ""
facets.each do |facet|
result << facet.render_for_search
end
result
end
end
end
This is because within the Class Facet you don’t have access to the template binding.
In order to call the
render_for_searchmethod you probably do something likeJust override your
initializemethod to take the current context as argument.The same applies to the params hash.
Then call
Otherwise, define the
render_for_searchmethod directly within theMyHelpermodule and don’t wrap it into a class.