So I am extending String
in an initializer that requires a model_path
function to be used:
class String
def foo(bar)
...
link_to(baz, baz_path(baz))
end
end
So to get it to work I add
include Rails.application.routes.url_helpers
Problem is now I can't even view the website because there are weird problems with using url_for
elsewhere:
wrong number of arguments (3 for 0..1)
</script>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
--<%= mathjax_tag %>------- this line is highlighted as the problem --
<%= csrf_meta_tags %>
</head>
<body>
If I remove that include, my application views get rendered successfully again. But remove that include, and my extension to the String class does not work anymore.
How can I keep the functionality of my function (I'm ok with moving it elsewhere if need be, so long as it's accessible to all of my models) and also keep the views rendered?