Some are commenting about how to render a custom 404 page, but that's
slightly tangential: by default if there's no matched route, Rails should
render it's 404 page, but you're not even getting to that point.
I think your fundamental problem is routing related: somehow, you've got a
route in your routes.rb such that "/site/about/register.php" is being
routed to a controller, and that controller seems to be trying to render
something based dynamically on a parameter.
Ideally you should only have restrictively-defined routes define for actual
known valid actions; anything else should not be routable and you can
either let Rails handle it with it's own 404 page or configure something
like Patrick suggests at the bottom of your routes file which renders a
specific action to handle it custom.
If you really have to define routes that are sufficiently vague that
invalid URLs might get routed to controllers, you should at least ensure
that actions are not rendering blindly; in other words *don't* ever do
something like this:
match "/site/:something", to: "pages#show"
class PagesController
def show
render action: params[:something]
end
end
In that above example you're catching potentially any params[:something]
without validation that it's something you know to be a valid page. Again,
if you have to have a setup like this, change that show action to
explicitly 404 anything other than what you know is valid:
class PagesController
def show
if ["tos", "privacy"].include?(params[:something].to_s)
render action: params[:something]
else
render status: 404, file: Rails.root.join("public/404.html")
end
end
end
On Mon, Feb 10, 2014 at 1:13 PM, John Lynch <[email protected]>wrote:
> Chris, you can use rescue_from in your controller, something like
>
> class ApplicationController < ActionController::Base
> rescue_from User::NotAuthorized, with: :deny_access # self defined exception
> rescue_from ActiveRecord::RecordInvalid, with: :show_errors
>
> rescue_from 'MyAppError::Base' do |exception|
> ...
> end
> end
>
>
>
> On Mon, Feb 10, 2014 at 11:04 AM, 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<http://myapp.example.com/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.
>
--
--
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.