0

In my coffee script file, I have this:

$('#map_of_users').html("<iframe src='/map/" + $(this).data('user_id') + "></iframe>"

Bots are crawling that file and thinking there's a URL to check out, so I in my log I get a routing error that looks like this

No route matches [GET] "/map/%22+$(this).data(%22user_id%22)"

I do want to track routing errors, so I can't ignore all of them, but having a large volume of these frivolous routing errors takes lots of unnecessary time.

Maybe one quick solution is to add all coffeescript files to the robots.txt file or everything in the app/assets/javascripts file. What is recommended?

Note: I also posted an incorrect solution which attempts to fix this in the routes.rb file, and I'm wondering why it doesn't work.

user1515295
  • 1,181
  • 11
  • 28
  • use `robots.txt` to tell bots not to go to specific urls. see http://stackoverflow.com/questions/18693766/rails-robots-txt-folders – Max Williams Feb 13 '15 at 14:26

1 Answers1

0

Note: This solution doesn't work. I posted it to hear feedback about why it doesn't work.

If you put this in routes.rb...

match '/map/%22+$(this).data(%22user_id%22)', :to => 'shared#unauthorized', via: [:get, :post]

Going to http://localhost:3000/map/%22+$(this).data(%22user_id%22) still yields this Routing Error:

No route matches [GET] "/map/%22+$(this).data(%22user_id%22)"

I'm guessing the router doesn't read %22 the same way the browser does ("). Is there a way to compensate in the router?

If I run "rake routes" in the console, it shows that the route is being read like this:

GET|POST /map/%2522+$(this).data(%2522user_id%2522)(.:format)

Rails might be double encoding by converting the % to its ASCII representation %25. Can that be prevented?

user1515295
  • 1,181
  • 11
  • 28