Reload or Add routes at runtime in Rails 3

In one of my project, we needed SEO friendly Menu urls like /brandy/cognac. For this, we added a generic route/:parent/:child/:grandchild at the bottom of routes.rb.

With this approach, there was an issue with invalid urls like /this/is/wrong being redirected to specified controller action.

To fix this, we used Menu names to generate specific urls. But the routes would become invalid if Admin changes the menu name.

So we needed a way to reload routes once the menu is updated.

I found a hack mentioned in this blog that allow us to add routes dynamically and also reload the routes.

We tried this and it worked.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s