我正在关注Ruby on Rails教程(http://ruby.railstutorial.org/chapters/a-demo-app#sec-modeling_demo_users)并成功完成了练习,直到第2.2.1节。
当我尝试加载在2.2.1中创建的任何用户资源(例如localhost:3000 / users和localhost:3000 / user / new)时遇到字符编码问题,这基本上是不合适的生成的-box代码:
C:\用户\丹尼斯\ rails_projects \ demo_app> rails generate scaffold用户名:string email:string
我的环境:
Rails返回以:
开头的错误页面用户#index
中的Encoding :: InvalidByteSequenceError显示C:/Users/Dennis/rails_projects/demo_app/app/views/layouts/application.html.erb第6行引发:
incomplete "\x00" on UTF-16LE (in C:/Users/Dennis/rails_projects/demo_app/app/assets/javascripts/users.js.coffee)
提取的来源(第6行):
3: <head> 4: <title>DemoApp</title> 5: <%= stylesheet_link_tag "application", :media => "all" %> 6: <%= javascript_include_tag "application" %> 7: <%= csrf_meta_tags %> 8: </head> 9: <body>
users.js.coffee的内容:
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
application.html.erb的内容:
<!DOCTYPE html>
<html>
<head>
<title>DemoApp</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
index.html.erb的内容:
<h1>Listing users</h1>
<table>
<tr>
<th>Name</th>
<th>Email</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @users.each do |user| %>
<tr>
<td><%= user.name %></td>
<td><%= user.email %></td>
<td><%= link_to 'Show', user %></td>
<td><%= link_to 'Edit', edit_user_path(user) %></td>
<td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New User', new_user_path %>
答案 0 :(得分:2)
将users.js.coffee
重命名为users.js
即可。