本文介绍了Rails 4 + ReactJS:“ SyntaxError:在隐式对象中不能有隐式值”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注Fernando Villalobos的



但是,当我访问 localhost:3000 / records ,出现以下错误:

  Records#index 
中的ExecJS :: RuntimeError语法错误:[stdin]:7:10:隐式对象
中的隐式值不能为
< title> Expenses< / title>
<%= stylesheet_link_tag应用程序,媒体:全部,数据-turbolinks-track =>真实%>
<%= javascript_include_tag应用程序, data-turbolinks-track =>真实%>
<%= csrf_meta_tags%>
< / head>
< body>

特别是,引起问题的行似乎是:

 <%= javascript_include_tag'application','data-turbolinks-track'=>真实%> 

任何关于探针是什么以及如何使事情起作用的想法?

解决方案

尝试使用以下脚本而不是当前的脚本(只需从该脚本中删除 React.DOM ):

  @Records = React.createClass 
呈现:->
div
className:'records'
h2
className:'title'
'Records'


I am following Fernando Villalobos' React.js - A guide for Rails developers AirPair tutorial.

The goal here is to build a simple expense tracking app, using Rails and React JS.

In the Nesting Components: Listing Records section, the author recommends to create a app/views/records/index.html.erb file as follows:

<%# app/views/records/index.html.erb %>
<%= react_component 'Records', { data: @records } %>

AND a javascripts/components/records.js.coffee file as follows:

# app/assets/javascripts/components/records.js.coffee

  @Records = React.createClass
    render: ->
      React.DOM.div
        className: 'records'
        React.DOM.h2
          className: 'title'
          'Records'

Then, when we visit localhost:3000/records, we are supposed to see the following:

However, when I visit localhost:3000/records, I get the following error:

ExecJS::RuntimeError in Records#index
SyntaxError: [stdin]:7:10: cannot have an implicit value in an implicit object
<title>Expenses</title>
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>
</head>
<body>

In particular, the line causing the issue seems to be:

<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>

Any idea of what the probelm is and how I can make things work?

解决方案

Try the following coffescript instead of your current coffescript(Just removing React.DOM from the coffescript):

@Records = React.createClass
  render: ->
    div
      className: 'records'
      h2
        className: 'title'
        'Records'

这篇关于Rails 4 + ReactJS:“ SyntaxError:在隐式对象中不能有隐式值”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-22 08:00