I have the following statement which does work although it uses eval:
def resource_name
self.class.to_s.match(/(.+)Controller/)[1].singularize
end
def collection
@collection ||= eval "#{resource_name}.all(sort: [[:name, :asc]])"
end
Is there a better way of doing this that does not use eval?
Use
Object#sendinstead, after you constantize the resource name: http://ruby-doc.org/core-1.9.3/Object.html#method-i-send