From: Emil Kampp Date: 2009-12-10T20:19:07+09:00 Subject: How do I ensure that File.write finished? Hi there. I am trying to make a form to update the values in a yml file (my applications configuration file). This is working kind of fine. Sometimes it works, sometimes not. I have confirmed (through logging) that a content for +string+ is always there. So there is always something trying to be written into the yml file, but still sometimes it ends up being empty. And an empty configuration file is no good! [code] # server-controller (user generated controller in rails) def update # This inserts a new setting into the hash unless params[:new_setting][:key].blank? and params[:new_setting][:value].blank? params[:settings].collect{ |env, settings| settings[params[:new_setting][:key].to_sym] = params[:new_setting][:value].to_s } end # This writes the hash to the file (See the second snippet for details) ServerSystem::update_configuration(params[:settings]) # Redirects to the action that restarts the server to load the new configurations redirect_to admin_server_restart_path end [/code] [code] # Custom class def update_configuration(settings) string = settings.to_yaml File.new(APP_CONFIG_FILE, "w").write string end [/code] The problem is that the setup is dodgy, sometimes it works, sometimes it looks like the server is restarted before the content of +string+ is written to the configuration file. How can I ensure that the content has been written before executing next line of code (the restart in this case)? -- Posted via http://www.ruby-forum.com/.