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):My mistake.
I was using Ruby "two-space" indentation in my CoffeeScript file, which caused the error.
When I copied and pasted the code from the tutorial, with the right indentation, everything worked like a charm.