Ed1
(Ed)
June 27, 2007, 2:35am
1
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
lanzm
(lanzm)
June 27, 2007, 6:15am
2
what do you get if do it like this:
<% Dir.chdir( "#{RAILS_ROOT}/public" ) %>
?
marcel
Ed1
(Ed)
June 28, 2007, 1:17pm
3
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/..