Question

I have a rather unique question that probably has a simple answer but I haven't been able to figure it out.

I am using rails 4.1 and creating an app that I want to accept urls that don't exist as part of a NFC tag registration process.

For example, let's say the app is located at example.com and I programmed an NFC tag with the url example.com/xyz123.

I don't want the rails app to spit out a 404 error but rather attribute that tag to the signed in User account and allow them to register that url to one of that users' personalized pages that they created.

I've dug into the docs on error handling but that doesn't seem to solve the problem and I can't seem to find where in the core API these requests are handled and how I might override them in the application.rb controller.

Was it helpful?

Solution

this is rather simple. just create a catch-all route

get '*path', to: 'tags#new'

the requested part will be params[:path]

i would recommend not having unscoped catch-all routes through. it's slow and a pita if you ever want to change your URL structure (you will want to do that at some point). always use some namespace www.some-url.com/t/xyz123

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top