# Rails cross platform problem

**URL:** <https://www.ruby-forum.com/t/rails-cross-platform-problem/162445>\
**Category:** Rails\
**Created:** [March 10, 2009, 1:43am UTC](https://www.ruby-forum.com/t/rails-cross-platform-problem/162445 "2009-03-10T01:43:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [March 10, 2009, 1:43am UTC](https://www.ruby-forum.com/t/rails-cross-platform-problem/162445/1 "2009-03-10T01:43:24Z")

</div>

My Rails working on a Linux system and a client access this server from  
Windows. The client inputs something in a text area and click submit, in  
the server side, it put the input into a file. The problem is that at  
the end of each line in the file, there is a “^M”. How can I avoid this?  
I use File.puts method to write to the file.

thanks.

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [March 10, 2009, 8:57pm UTC](https://www.ruby-forum.com/t/rails-cross-platform-problem/162445/2 "2009-03-10T20:57:26Z")

</div>

This is related to the fact that on \*nix the default end of line  
character is \n, and on windows, it’s \r\n (note that this is not Ruby  
specific, but platform specific - Ruby is just following along).

There’s a utility on unixes called unix2dos which you can use to  
substitute all \n characters to \r\n, or if you need to stay in Ruby-  
land, use gsub with something like gsub!(/\n/,"\r\n").

Hope that helps,  
-H
