Recursively redirecting in Rails 3 Routes -


We are updating our large web app and getting rid of our URL synonyms system. For example, although we only use a model for 'advertiser', but it is kept for 'merchants' and 'vendors' using synonyms. Thus, / merchants / 1 and / vendor / 1 advertisers use the same exact controller and verb.

Now we do not need this functionality, but we provide users with the appropriate place (i.e. the proper controller functions) for the old URL.

So far I've tried:

1) Reading - This leads me to try the following suggestions

2) match / merchants '= & Gt; Redirect ('/ Advertiser') - This did not work at all, although the syntax looks correct. 3) Moving on resources (it produces one TON of routes and can cause insecurity):

  ADVERTISER_SYNONOYMS = ['affiliates',' vendors '] ADVERTISER_SYNONYMS.each | A | Resources: Advertiser ,: Path = & gt; A, as: = & gt; : Advertiser Resources: Members receive other members: Test Match: Generated_state and End End   

We use nested resources in our routes. RB, so I am struggling to become a synonym for all of the more complex URLs recognized if anyone has dealt with this problem or has given it a more elegant suggestion, then I would be most grateful.

There are several ways to handle it in such a way, such as routes.rb , or at the webserver level like Apache or NGNX.

I have a solution gem like; It keeps the routes clean and the rules are simple ruby, it provides a set of ways to configure rewriting and redirection. For your situation, I want to use a permanent redirect. If I have not tested it myself, then something like this can work for you:

  #filefile gem 'rack-rewrite' # application.rb config.middleware.use (rack: : Reverse) r301% r [/ merchant vendor] / (\ w +)}, '/ advertiser / $ 1' end    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -