但是在一开始我得到一个错误:
I18n::InvalidLocaleData in Users#index
Showing .../app/views/users/index.html.erb where line #1 raised:
can not load translations from .../config/locales/en.yml, expected it to return a hash, but does not
index.html.erb:
<% provide(:title, t('users.index.title.site_title')) %>
<h1><%= t 'users.index.title.head' %></h1>
<%= form_tag users_path, :method => 'get' do %>
<%= hidden_field_tag :direction, params[:direction] %>
<%= hidden_field_tag :sort, params[:sort] %>
<p>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag (t 'users.index.search_form.search'), :name => nil %>
</p>
<% end %>
配置/区域设置/ en.yml
en:
users:
index:
title:
site_title: "Users"
head: "Users"
search_form:
search: "Search"
答案 0 :(得分:6)
区域设置数据应缩进两个空格,而不是四个,因此正确的版本为:
en:
users:
index:
title:
site_title: "Users"
head: "Users"
search_form:
search: "Search"
另外,检查您是否使用空格或制表符,后者会导致麻烦。