Ruby on rails 出于某种原因,将组件呈现反应为字符串

Ruby on rails 出于某种原因,将组件呈现反应为字符串,ruby-on-rails,reactjs,react-rails,Ruby On Rails,Reactjs,React Rails,出于某种原因,我的React组件的某些部分正在呈现为字符串 我将Rails与react Railsgem一起使用,而sprockets coffee reactgem将JSX与Coffeescript一起使用 这是密码 show.html.erb <%= react_component 'ArticleForm', {action: articles_path, authenticity_token: form_au

出于某种原因,我的React组件的某些部分正在呈现为字符串

我将Rails与
react Rails
gem一起使用,而
sprockets coffee react
gem将JSX与Coffeescript一起使用

这是密码

show.html.erb

<%= react_component 'ArticleForm', {action: articles_path, 
                                    authenticity_token: form_authenticity_token,
                                    collection_id: @collection.id,
                                    } %>

文章_form.js.coffee.cjsx

window.ArticleForm = React.createClass
  getInitialState: ->
    metadata: {}
    url: ''

  handleChange: ->
    console.log('test')

  render: ->
    <form accept-charset="UTF-8" action={this.props.action} method="post">
      <AuthenticityTokenInput authenticity_token={this.props.authenticity_token} />
    </form>
window.AuthenticityTokenInput = React.createClass
  render: ->
    <div style={{margin: 0, padding: 0, padding: 'inline'}}>
      <input name="utf8" type="hidden" value="✓">
      <input name="authenticity_token" type="hidden" value={this.props.authenticity_token}>
    </div>
window.ArticleForm=React.createClass
getInitialState:->
元数据:{}
url:“”
handleChange:->
console.log('test')
渲染:->
Authentity_token_input.js.coffee.cjsx

window.ArticleForm = React.createClass
  getInitialState: ->
    metadata: {}
    url: ''

  handleChange: ->
    console.log('test')

  render: ->
    <form accept-charset="UTF-8" action={this.props.action} method="post">
      <AuthenticityTokenInput authenticity_token={this.props.authenticity_token} />
    </form>
window.AuthenticityTokenInput = React.createClass
  render: ->
    <div style={{margin: 0, padding: 0, padding: 'inline'}}>
      <input name="utf8" type="hidden" value="✓">
      <input name="authenticity_token" type="hidden" value={this.props.authenticity_token}>
    </div>
window.AuthenticityTokenInput=React.createClass
渲染:->
以及输出:

出于某种原因,它将两个输入呈现为纯文本,而不是实际的html标记

当我检查元素时,我得到的是:

<form action="/articles" method="post" data-reactid=".0">
    <div style="margin:0;padding:inline;" data-reactid=".0.0">
        <span data-reactid=".0.0.0">&lt;input name="utf8" type="hidden" value="✓"&gt;
&lt;input name="authenticity_token" type="hidden" value=</span>
        <span data-reactid=".0.0.1">zlZevmHku5ZU+UA998KwmJHAMn94uVkilrBj1iC/A8o=</span>
        <span data-reactid=".0.0.2">&gt;</span>
    </div>
</form>

输入name=“utf8”type=“hidden”值=”✓"
输入name=“authenticity\u token”type=“hidden”值=
zlZevmHku5ZU+UA998KwmJHAMn94uVkilrBj1iC/A8o=

如果在使用CJSX时遇到以纯文本形式输出的标记,通常原因是其中一个内部标记的格式不正确

在您的情况下,应该是自动关闭的
标记。在CJSX(和JSX)中,您必须提供关闭标记或使标记自动关闭,例如

更正后的
authenticity\u token\u input.js.coffee.cjsx
如下所示:

window.AuthenticityTokenInput = React.createClass
  render: ->
    <div style={{margin: 0, padding: 0, padding: 'inline'}}>
      <input name="utf8" type="hidden" value="✓" />
      <input name="authenticity_token" type="hidden" value={this.props.authenticity_token} />
    </div>
window.AuthenticityTokenInput=React.createClass
渲染:->