Dir.chdir causes application error

I am getting an application error when I try to use Dir.chdir in a layout

<% Dir.chdir('public') %>

The complete dump from development.log is listed below.

When I try the same thing in the console, it works fine.

Loading development environment.

Dir.chdir('public')

=> 0

Any ideas on what the problem is, or how to fix it?

Thanks

Output from development.log

what do you get if do it like this:

<% Dir.chdir( "#{RAILS_ROOT}/public" ) %>

?

marcel

This produces the same error.

rails is looking for a session file relative to the current working directory, which is normally RAILS_ROOT. but when you did a chdir, you changed the current directory and now rails can't find the session file it wants.

answer is don't change the working directory. why would you need to?

meant to show an example

Loading development environment.

Dir.getwd

=> "/home/chall/MyApp"

Dir.chdir('public')

=> 0

Dir.getwd

=> "/home/chall/MyApp/public"

RAILS_ROOT

=> "script/../config/../config/.."

so now, if rails tries to load a file using RAILS_ROOT, it will look in

/home/chall/MyApp/public/script/../config/../config/..

instead of

/home/chall/MyApp/script/../config/../config/..