Default routes for unknown actions

Hi folks-

I have the following map for default ‘junk’ routes:

map.connect ‘*anything’, :controller => ‘welcome’, :action =>
‘unknown’

Which works just fine for a URL like: “mysite.com/junkjunkjunk

However, it still tries to resolve an action when I do:
mysite.com/my_controller/junkjunkjunk

How can I send Rails to a default route in the case of an unknown
action? Currently, I get the standard “Unknown action… No action
responded to junkjunkjunk”

Jake

Jake J. wrote:

I have the following map for default ‘junk’ routes:

map.connect ‘*anything’, :controller => ‘welcome’, :action =>
‘unknown’

Which works just fine for a URL like: “mysite.com/junkjunkjunk

However, it still tries to resolve an action when I do:
mysite.com/my_controller/junkjunkjunk

Please show the complete routes setup, so we can help you.

How can I send Rails to a default route in the case of an unknown
action? Currently, I get the standard “Unknown action… No action
responded to junkjunkjunk”

It should work if you put the following action in your application
controller. Please read the documentation for rescue_action_in_public
before returning with questions (because this method is not invoked
for local clients).

def rescue_action_in_public(exception)
case exception
when ActionController::UnknownAction
render :file => “#{RAILS_ROOT}/public/404.html”, :status => 404
else
logger.error "Error raised: " + exception.to_s
render :file => “#{RAILS_ROOT}/public/500.html”, :status => 500
end
end

I actually also redirect to 404 when a ActiveRecord::RecordNotFound
exception is encountered.

Regards,
Patrice

def rescue_action_in_public(exception)
case exception
when ActionController::UnknownAction
render :file => “#{RAILS_ROOT}/public/404.html”, :status => 404
else
logger.error "Error raised: " + exception.to_s
render :file => “#{RAILS_ROOT}/public/500.html”, :status => 500
end
end

Ah. That explains a lot. Thanks. I didn’t even know this function
existed. The hard part is rarely the search. It’s knowing what to
search for.

Jake