There are many ways to tackle this problem, but this is what I'm using.

# 404s
scope :constraints => lambda{|req| !req.path.match(/(gif|jpg|png)/) } do
  match '*path', :to => 'pages#error'
end

This goes in config/routes.rb and is the last route. So, basically, any request 
that is not an image and has not been matched by a valid route, gets treated as 
a 404 error.

I haven't run into the same particular spam link issue as you, but you could 
use a scoped constraint to ignore all paths that contain and/or end with .php.

-- Patrick



On Feb 10, 2014, at 8:04 pm, Chris McCann <[email protected]> wrote:

> One of my Rails apps sent me this exception notification:
> 
> A ActionView::MissingTemplate occurred in site#about:
> 
>   Missing template site/about.erb in view path app/views
> 
> -------------------------------
> Request:
> -------------------------------
> 
>   * URL       : http://myapp.example/site/about/register.php
>   * Parameters: {"format"=>"php", "action"=>"about", "id"=>"register", 
> "controller"=>"site"}
> 
> My google-fu is weak on this one -- what's a good way to prevent this type of 
> bogus request from throwing an exception application-wide?
> 
> Cheers,
> 
> Chris
> 
> -- 
> -- 
> SD Ruby mailing list
> [email protected]
> http://groups.google.com/group/sdruby
> --- 
> You received this message because you are subscribed to the Google Groups "SD 
> Ruby" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
--- 
You received this message because you are subscribed to the Google Groups "SD 
Ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to