The following Ruby code causes extra lines to be written, and I am trying to find out what is causing that.
My Ruby code:
File.delete(RAILS_ROOT + '/app/views/filer/' + @navn + ".html.erb")
filen = File.open(RAILS_ROOT + '/app/views/filer/' + @app.slug + ".html.erb", "a+")
filen.write("#{params[:app][:cod]}")
I have inspected the params:
Content-Disposition: form-data; name="app[cod]" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="da"> <head> <title>Ruby on Rails: Welcome aboard</title> <%= javascript_include_tag 'jquery' %>
But when the file is created there are added new lines:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="da">
<head> <title>Ruby on Rails: Welcome aboard</title>
<%= javascript_include_tag 'jquery' %>
When it should be:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="da">
<head> <title>Ruby on Rails: Welcome aboard</title>
<%= javascript_include_tag 'jquery' %>
And here is an inpection with the rails inspect:
"cod"=>"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"da\">\r\n<head>
I used the gsub method to get rid of the new lines: