3

我正在关注 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)时遇到字符编码问题,这基本上是开箱即用的代码生成:

C:\Users\Dennis\rails_projects\demo_app> rails 生成脚手架用户名:字符串电子邮件:字符串

我的环境:

  • Windows 7 64 位
  • 红宝石 1.9.3p194 (2012-04-20) [i386-mingw32]
  • 导轨 3.2.9

Rails 返回一个错误页面,开头为:

用户#index 中的编码::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 %>
4

1 回答 1

2

重命名users.js.coffeeusers.js将起作用。

于 2012-11-14T05:11:27.593 回答