所以我有Rails应用程序,我安装了react Rails gem,设置它并try 运行测试应用程序.

刚安装,当我试图运行hello world程序时,出现了以下错误:

未捕获引用错误:未定义ReactDOM

这是我的react :

var HelloWorld = React.createClass({
  render: function() {
    return (
      <p>
        Hello, <input type="text" placeholder="Your name here" />!
        It is {this.props.date.toTimeString()}
      </p>
    );
  }
});

setInterval(function() {
  ReactDOM.render(
    <HelloWorld date={new Date()} />,
    document.getElementById('example')
  );
}, 500);

它保存在/app/assets/javascripts/components/test中.js.jsx文件.

带有Ruby 2.2.3的Rails 4.2.4

推荐答案

ReactDOM版本从0.14.0版开始提供,所以您需要使用React.render(因为您有React 0.13.3版),

setInterval(function() {
  React.render(
    <HelloWorld date={new Date()} />,
    document.getElementById('example')
  );
}, 500);

或者升级你的React版,包括ReactDOM

Changes in React 0.14

Ruby-on-rails相关问答推荐

在控制器操作中适当使用ActiveModel Dirty

Rails 6升级没有加载Mongoid,这是一个问题

使用Rails和RSpec,有没有办法查看操作真正将您带到哪个页面?

删除 aws s3 (rails7) 上的日志(log)文件

为什么是 json.partial!使用新的哈希语法传递本地时,jbuiler 模板中的行不执行?

Rails 'includes' 和 'where' 与 belongs_to 和 has_many 关联

ViewModel 和 Controller 有什么区别?

如何在 Rails 中注释掉 ERB?

NameError:未定义的局部变量或方法记录器

如何使用 Rails 3 / Rack 在没有 www 的情况下重定向?

rails, activerecord, 获取当前连接规范

如何让 Rspec 运行嵌套在文件夹下的所有测试?

在 where 查询中查找 nil has_one 关联

错误未初始化的常量 AWS (NameError)

为什么 Ruby on Rails 使用 http://0.0.0.0:3000 而不是 http://localhost:3000?

Active Record has_many:通过删除一条关联记录

Ruby on Rails:如何为 postgresql 编辑 database.yml?

停止 Rails 为视图和助手生成规范测试?

sass-rails 助手image-url、asset-url在 rails 3.2.1 中不起作用

Rails.cache 在测试之间被清除了吗?