title: Rails does not generate an authenticity token
body: <p>I'm following these two tutorials altogether, </p>
  
  <ul>
  <li><p><a href="https://www.airpair.com/reactjs/posts/reactjs-a-guide-for-rails-developers" rel="nofollow noreferrer">https://www.airpair.com/reactjs/posts/reactjs-a-guide-for-rails-developers</a></p></li>
  <li><p><a href="https://facebook.github.io/react/docs/tutorial.html" rel="nofollow noreferrer">https://facebook.github.io/react/docs/tutorial.html</a></p></li>
  </ul>
  
  <p>and implementing a simple comment system in Rails. However, I got a problem with handling the submit. I implemented a simple AJAX POST request to send my form data (as state). It looks like this:</p>
  
  <pre><code>var CommentForm = React.createClass({
      handleChange: function(e) {
      var name, obj;
      name = e.target.name;
      return this.setState((
        obj = {},
        obj["" + name] = e.target.value,
        obj
      ));
    },
      handleSubmit: function(e) {
          e.preventDefault();
          var author = React.findDOMNode(this.refs.author).value.trim();
          var text   = React.findDOMNode(this.refs.text).value.trim();
          if(!text || !author) {
              return;
          }
          $.post(this.props.postUrl, {comment: this.state}, null, "application/json");
          React.findDOMNode(this.refs.author).value = '';
          React.findDOMNode(this.refs.text).value = '';
      },
      render: function() {
          return (
              &lt;form className="commentForm" onSubmit={this.handleSubmit}&gt;
          &lt;input type="text" placeholder="Your name" ref="author" name="author" onChange={this.handleChange} /&gt;
          &lt;input type="text" placeholder="Say something..." ref="text" name="text" onChange={this.handleChange} /&gt;
          &lt;input type="submit" value="Post" /&gt;
        &lt;/form&gt;
          );
      }
  });
  </code></pre>
  
  <p>As I examined the console, It looks like it is passing to the right route and the right params, except no authenticity_token param. Here is a screen shot of what is in the console.</p>
  
  <p><a href="https://i.stack.imgur.com/6X0Ig.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6X0Ig.png" alt="enter image description here"></a></p>
  
  <p>In the first link that I've provided, it is said that jquery_ujs handles generating and passing an authenticity token to Ajax POST. However, this is not true in my case. What am I missing?</p>
  
  <p><strong>Edit:</strong>
  I've got a few answers that would fix my problem. However, I'm still curios about what makes the difference between my code and the code at this tutorial?</p>