-1

I have a strange requirement that I need to inject a value at the beginning of all local links. This is a legacy app and is quite large so I'm looking to do it under the hood, maybe with a monkey patch.

Basically if I have a link_to "Go to dashboard", dashboard_path or link_to "Create a new Job", new_job_path that they would both generate links that look like "/some_value/dashboard" and "/some_value/jobs/new"

Tried a few things and they all have failed. Any ideas?

1 Answers1

0

You can try something like this in your helper instead of monkey patching link_to.

 def custom_link_to(link, url, opts={})
    url = "append_here/"+url
    link_to(link, url, opts)
  end

Now you can call this action instead of calling link_to wherever applicable and also use link_to in case if you don't want to override.

custom_link_to("Go to Dashboard",dashboard_path,{})

UPDATE

In case of overriding everything, something similar to this might be helpful - Monkey patching Rails