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

Processing LeagueController#index (for 71.74.192.170 at 2007-06-26
22:28:42) [GET]
Session ID: c2618c4e3154c6d62f1c6dd055a9deb1
Parameters: {“action”=>“index”, “controller”=>“league”}

Errno::ENOENT (No such file or directory - script/…/config/…/tmp/
sessions//ruby_sess.6117ae9afe83d621):
/usr/lib/ruby/1.8/pstore.rb:295:in initialize' /usr/lib/ruby/1.8/pstore.rb:295:inopen’
/usr/lib/ruby/1.8/pstore.rb:295:in transaction' /usr/lib/ruby/1.8/cgi/session/pstore.rb:81:inupdate’
/usr/lib/ruby/1.8/cgi/session/pstore.rb:88:in close' /usr/lib/ruby/1.8/cgi/session.rb:324:inclose’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/base.rb:1184:in close_session' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/base.rb:1228:inprocess_cleanup_without_flash’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/flash.rb:146:in process_cleanup_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/filters.rb:662:inprocess_cleanup_without_session_management_support’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/session_management.rb:124:in
process_cleanup_without_components' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/components.rb:178:inprocess_cleanup’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/base.rb:435:in process_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/filters.rb:624:inprocess_without_session_management_support’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/session_management.rb:114:in process' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/base.rb:330:inprocess’
/usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in
dispatch' /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb: 113:inhandle_dispatch’
/usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb:
79:in service' /usr/lib/ruby/1.8/webrick/httpserver.rb:104:inservice’
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in run' /usr/lib/ruby/1.8/webrick/server.rb:173:instart_thread’
/usr/lib/ruby/1.8/webrick/server.rb:162:in start' /usr/lib/ruby/1.8/webrick/server.rb:162:instart_thread’
/usr/lib/ruby/1.8/webrick/server.rb:95:in start' /usr/lib/ruby/1.8/webrick/server.rb:92:ineach’
/usr/lib/ruby/1.8/webrick/server.rb:92:in start' /usr/lib/ruby/1.8/webrick/server.rb:23:instart’
/usr/lib/ruby/1.8/webrick/server.rb:82:in start' /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb: 63:indispatch’
/usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/
webrick.rb:59
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in
gem_original_require' /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:inrequire’
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/
dependencies.rb:495:in require' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/ dependencies.rb:342:innew_constants_in’
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/
dependencies.rb:495:in require' /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39 /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:ingem_original_require’
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require’
script/server:3

Rendering /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/templates/rescues/layout.rhtml (500 Internal Error)
No such file or directory - script/…/config/…/tmp/sessions//
ruby_sess.6117ae9afe83d621
/usr/lib/ruby/1.8/pstore.rb:295:in initialize' /usr/lib/ruby/1.8/pstore.rb:295:inopen’
/usr/lib/ruby/1.8/pstore.rb:295:in transaction' /usr/lib/ruby/1.8/cgi/session/pstore.rb:81:inupdate’
/usr/lib/ruby/1.8/cgi/session/pstore.rb:88:in close' /usr/lib/ruby/1.8/cgi/session.rb:324:inclose’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/
base.rb:1184:in close_session' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ base.rb:1228:inprocess_cleanup_without_flash’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/
flash.rb:146:in process_cleanup_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ filters.rb:662:inprocess_cleanup_without_session_management_support’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/
session_management.rb:124:in process_cleanup_without_components' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ components.rb:178:inprocess_cleanup’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/
base.rb:435:in process_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ filters.rb:624:inprocess_without_session_management_support’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/
session_management.rb:114:in process' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ base.rb:330:inprocess’
/usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in
dispatch' /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb:113:inhandle_dispatch’
/usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb:79:in
service' /usr/lib/ruby/1.8/webrick/httpserver.rb:104:inservice’
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in run' /usr/lib/ruby/1.8/webrick/server.rb:173:instart_thread’
/usr/lib/ruby/1.8/webrick/server.rb:162:in start' /usr/lib/ruby/1.8/webrick/server.rb:162:instart_thread’
/usr/lib/ruby/1.8/webrick/server.rb:95:in start' /usr/lib/ruby/1.8/webrick/server.rb:92:ineach’
/usr/lib/ruby/1.8/webrick/server.rb:92:in start' /usr/lib/ruby/1.8/webrick/server.rb:23:instart’
/usr/lib/ruby/1.8/webrick/server.rb:82:in start' /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb:63:indispatch’
/usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/
webrick.rb:59
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in
gem_original_require' /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:inrequire’
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/
dependencies.rb:495:in require' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/ dependencies.rb:342:innew_constants_in’
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/
dependencies.rb:495:in require' /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39 /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:ingem_original_require’
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require’
script/server:3

what do you get if do it like this:

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

?

marcel

On Jun 27, 2:15 am, lanzm [email protected] wrote:

what do you get if do it like this:

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

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/…