title: Save user input as it is - Ruby on Rails
body: <p>I am trying to create an Online Judge where users will write/paste c++ code to evaluate it. I'm using rails 6 and <strong>Ruby 2.6.1</strong> . The problem is users' input can contain any type characters <strong>\n</strong>,<strong>\t</strong> etc . I need to save it to a cpp file as it is. For example a user is submitting the following code:</p>
  
  <pre><code>#include&lt;bits/stdc++.h&gt;
  using namespace std;
  
  int main()
  {
      cout &lt;&lt; "Hello World\n";
  }
  </code></pre>
  
  <p><strong>I am using the following Ruby method to save the user input to a file</strong></p>
  
  <p><code>system("echo '#{params[:code]}' &gt; code.cpp")</code></p>
  
  <p>My expected output is to be same as the user input. But I'm getting the following output to the saved file.</p>
  
  <pre><code>#include&lt;bits/stdc++.h&gt;
  using namespace std;
  
  int main()
  {
  cout &lt;&lt; "Hello World
  ";
  }
  </code></pre>
  
  <p>Which is problematic, because it results in compilation error. So my question is how can I <strong>SAFELY</strong> save the users' input as it is. </p>