Routes.rb and static html files in public/

Hi,

I’ve read posts on approaches to handling static files, but my question
is a little different.

I am mixing and matching dynamic and static pages for an “employee”
section of a website.

So I have
apps/controller/employee_controller.rb and associated view stuff.

But I also have
public/employee/*.html

But of course if I trying this:

http://localhost:3000/employee/main.html

I get:
Action Controller: Exception caught
Unknown action
No action responded to main.html

How would I use routes.rb to by-pass EmployeeController when the request
ends in .html, so that Rails justs looks in public/employee/ for such
requests?

Or do I really need different names so the controller and
public/employee/ don’t clash?

Thanks.

Paul

It’s working now. I added this to routes.rb:

map.connect “employee/:name”, :controller => “employee”, :action =>
“show_page”, :section => “employee”

And now this works:
http://localhost:3000/employee/main
(dynamically rendering a page via show_page action and corresponding
template)

And this works:
http://localhost:3000/employee/main.html
(rendering the static file public/employee/main.html and by-passing the
controller)

Now I just need to figure out why it works…

Cheers

Paul H. wrote:

apps/controller/employee_controller.rb and associated view stuff.
Unknown action
No action responded to main.html

How would I use routes.rb to by-pass EmployeeController when the request
ends in .html, so that Rails justs looks in public/employee/ for such
requests?

Or do I really need different names so the controller and
public/employee/ don’t clash?

Yes I think you already have the answer.

On Oct 6, 2006, at 4:31 PM, Paul H. wrote:

And this works:
http://localhost:3000/employee/main.html
(rendering the static file public/employee/main.html and by-passing
the
controller)

Now I just need to figure out why it works…

I bet the reason is

  1. First the web server looks for a static resource

2a. If it finds it on disk it serves it

2b. Otherwise it calls the Rail’s dispatcher

If that’s correct you are going through 2a.

– fxn

On Oct 6, 2006, at 4:52 PM, Xavier N. wrote:

And this works:

2a. If it finds it on disk it serves it

2b. Otherwise it calls the Rail’s dispatcher

If that’s correct you are going through 2a.

Well, that certainly does not coincide with the reported behaviour at
the beginning of the thread, but it is certainly what WEBrick does:

def service(req, res) #:nodoc:
unless handle_file(req, res)
begin
REQUEST_MUTEX.lock unless
ActionController::Base.allow_concurrency
unless handle_dispatch(req, res)
raise WEBrick::HTTPStatus::NotFound, “`#{req.path}’ not
found.”
end
ensure
unless ActionController::Base.allow_concurrency
REQUEST_MUTEX.unlock if REQUEST_MUTEX.locked?
end
end
end
end

If handle_file() succeeds Rails is not reached.

– fxn