Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在选项哈希中带有{prerender:true}的React rails:Component给出了一个V8:Error-Unexpected标记<;_Ruby On Rails_Ruby On Rails 4_V8_Reactjs_Execjs - Fatal编程技术网

Ruby on rails 在选项哈希中带有{prerender:true}的React rails:Component给出了一个V8:Error-Unexpected标记<;

Ruby on rails 在选项哈希中带有{prerender:true}的React rails:Component给出了一个V8:Error-Unexpected标记<;,ruby-on-rails,ruby-on-rails-4,v8,reactjs,execjs,Ruby On Rails,Ruby On Rails 4,V8,Reactjs,Execjs,我正在一个项目中使用gem 每当我将prerender:true选项传递给react\u组件helper方法的选项哈希时,我都会得到错误:V8::error-意外标记 `嗨,世界` #该文件位于以下文件中: #./apps/assets/javascripts/components/assignment/AssignmentWindows.js.jsx.coffee 堆栈跟踪: V8::Error - Unexpected token < at <eval>:19037:15

我正在一个项目中使用gem

每当我将
prerender:true
选项传递给
react\u组件
helper方法的选项哈希时,我都会得到错误:
V8::error-意外标记
`嗨,世界`
#该文件位于以下文件中:
#./apps/assets/javascripts/components/assignment/AssignmentWindows.js.jsx.coffee
堆栈跟踪:

V8::Error - Unexpected token < at <eval>:19037:15:
  therubyracer (0.12.1) lib/v8/error.rb:86:in `block in try'
  therubyracer (0.12.1) lib/v8/error.rb:83:in `try'
  therubyracer (0.12.1) lib/v8/context.rb:95:in `block in eval'
  therubyracer (0.12.1) lib/v8/context.rb:248:in `block (2 levels) in lock_scope_and_enter'
  therubyracer (0.12.1) lib/v8/context.rb:245:in `block in lock_scope_and_enter'
  therubyracer (0.12.1) lib/v8/context.rb:244:in `lock_scope_and_enter'
  therubyracer (0.12.1) lib/v8/context.rb:204:in `enter'
  therubyracer (0.12.1) lib/v8/context.rb:94:in `eval'
  execjs (2.2.0) lib/execjs/ruby_racer_runtime.rb:11:in `block in initialize'
  execjs (2.2.0) lib/execjs/ruby_racer_runtime.rb:78:in `block in lock'
  execjs (2.2.0) lib/execjs/ruby_racer_runtime.rb:76:in `lock'
  execjs (2.2.0) lib/execjs/ruby_racer_runtime.rb:9:in `initialize'
  execjs (2.2.0) lib/execjs/runtime.rb:44:in `compile'
  execjs (2.2.0) lib/execjs/module.rb:27:in `compile'
  ... end of execjs errors ...
V8::错误-意外令牌
谢谢大家的帮助

从中复制答案

要将JSX转换为JS,只需创建.JS.JSX文件。这些 文件将根据请求进行转换,或作为 资产:预编译任务

也可以通过创建.js.jsx.coffee文件来使用CoffeeScript文件。 我们还需要在backticks中嵌入JSX,以便CoffeeScript忽略 它不懂语法。下面是一个例子:

Component=React.createClass
渲染:->
``

请注意文件扩展名。

恐怕我不用咖啡。。。或者是ruby。但我可以告诉你,问题是,无论你用什么来编译咖啡的jsx->standard coffee都不起作用。也许您需要这样的东西:rails资产管道将首先将其从coffee编译为jsx。backticks告诉coffee忽略backticks中包含的内容,并将其传递给javascript。在本例中,coffeescript将其传递给jsx转换器。我认为它在服务器端呈现时没有通过jsx转换器。看起来我们有一个测试正在运行服务器生成的东西,它使用了coffeescript,所以应该可以正常工作。我还没有做过这方面的工作,但看起来我们需要一个
components.js
文件,用于服务器渲染。我想你正在这么做,但也许我们有一个错误,当我们加载到虚拟机的文件?嗨,保罗。我的
components.js.coffee
文件位于
app/assets/javascripts/
dir中。它只是有这样一行:
#=require_tree./components
您可能想尝试使用,因为这是一个比backticks更干净的解决方案。我已经积极使用了一个多月,取得了巨大成功。
= react_component("AssignmentWindowProgressBar", { assignment: @assignment_json }, { prerender: true })
###* @jsx React.DOM ###

@AssignmentWindowProgressBar = React.createClass
  render: ->
    `<div>Hi world.</div>`

# this is located in this file:
# ./apps/assets/javascripts/components/assignments/AssignmentWindows.js.jsx.coffee
V8::Error - Unexpected token < at <eval>:19037:15:
  therubyracer (0.12.1) lib/v8/error.rb:86:in `block in try'
  therubyracer (0.12.1) lib/v8/error.rb:83:in `try'
  therubyracer (0.12.1) lib/v8/context.rb:95:in `block in eval'
  therubyracer (0.12.1) lib/v8/context.rb:248:in `block (2 levels) in lock_scope_and_enter'
  therubyracer (0.12.1) lib/v8/context.rb:245:in `block in lock_scope_and_enter'
  therubyracer (0.12.1) lib/v8/context.rb:244:in `lock_scope_and_enter'
  therubyracer (0.12.1) lib/v8/context.rb:204:in `enter'
  therubyracer (0.12.1) lib/v8/context.rb:94:in `eval'
  execjs (2.2.0) lib/execjs/ruby_racer_runtime.rb:11:in `block in initialize'
  execjs (2.2.0) lib/execjs/ruby_racer_runtime.rb:78:in `block in lock'
  execjs (2.2.0) lib/execjs/ruby_racer_runtime.rb:76:in `lock'
  execjs (2.2.0) lib/execjs/ruby_racer_runtime.rb:9:in `initialize'
  execjs (2.2.0) lib/execjs/runtime.rb:44:in `compile'
  execjs (2.2.0) lib/execjs/module.rb:27:in `compile'
  ... end of execjs errors ...
Component = React.createClass
  render: ->
    `<ExampleComponent videos={this.props.videos} />`