1

I had a route that is used across my app as foo_path => /foo

Now I'm migrating this route to another app which defines the URL path differently /deep/path and also name the query_paramters used in the past by foo_path controller differently.

I'm looking to override the foo_path method so that now it returns /deep/path instead of /foo when called in view, controllers ... while transforming some query parameters names

I found some answer on stackoverflow but the method they use seem not to be working anymore on rails 4.2.7 which is the rails version I'm currently using.

How can I override foo_path method across the all app so that it returns /deep/path instead of /foo in rails 4.2.7 while being able to manipulate query_parameters ?

BentoumiTech
  • 1,627
  • 14
  • 21
  • Do you want to change `foo_path` to point to a completely different application? If so, you can remove it from `routes.rb` and define it in `ApplicationHelper`. – Greg Navis Oct 26 '17 at 11:21

1 Answers1

0

What you need to do is to have a named route.

For example, lets say your old path was identified as foo and you accessed it as foot_path.

Then you can do some thing like this in routes.rb.

'/bar', to: 'controller#action', as: :foo

That way foo_path will now give /bar

ref: http://guides.rubyonrails.org/routing.html#overriding-the-named-helpers

Ziyan Junaideen
  • 3,270
  • 7
  • 46
  • 71
  • I tried to simplify the problem in my question but in reality, I need `foo_path` method to return `/deep/path/` with some transformations in the query parameters name. I'll update my question to reflect that issue better. Thanks ! – BentoumiTech Oct 26 '17 at 06:22