我想使用i18n系统翻译rails表单.
我的模型属性已正确翻译,但是当我想翻译提交操作时,模型名称不会被翻译.
这是我的fr.yml语言环境文件
fr:
activerecord:
model:
character:
one: "Personnage"
other: "Personnages"
attributes:
character:
name: "Nom"
title: "Titre"
biography: "Biographie"
helpers:
submit:
update: "Mise à jour %{model}"
Run Code Online (Sandbox Code Playgroud)
我的_form.html.erb是
<%= form_for(@character) do |f| %>
<% if @character.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@character.errors.count, "error") %> prohibited this character from being saved:</h2>
<ul>
<% @character.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= …Run Code Online (Sandbox Code Playgroud) 我停用了用户注册(Gem Devise),并且想进行测试以确保路由/users/sign_up不存在。
为此,我在 spec/features/user_spec.rb
require 'spec_helper'
require 'capybara/rspec'
feature "Users" do
scenario "could not register " do
expect(:get => "/users/sign_up").not_to be_routable
end
end
Run Code Online (Sandbox Code Playgroud)
当我运行此测试时,出现以下错误:
1) Users could not register
Failure/Error: expect(:get => "/users/sign_up").not_to be_routable
NoMethodError:
undefined method `routable?' for {:get=>"/users/sign_up"}:Hash
# ./spec/features/user_spec.rb:8:in `block (2 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud) 我使用正交投影制作了地图,并尝试提高性能,因为旋转不平滑(大约 6-7FPS)。
这是一张用 topojson 文件 (world-100m) 构建的世界地图。我需要与 country 进行交互并对它们进行着色,因此svg:path 与 countries 的数量一样多。
加载后,我使用 d3.timer 启动了自动旋转功能:
autoRotate = () =>
@start_time = Date.now() # Store the current time (used by automatic rotation)
d3.timer () =>
dt = Date.now() - @start_time
if @stopRotation or dt > @config.autoRotationDuration
true
else
@currentRotation[0] = @currentRotation[0] - @config.autoRotationSpeed
@projection.rotate @currentRotation
redrawPathsOnRotationOrScale(@currentRotation, @projection.scale())
false
redrawPathsOnRotationOrScale = (rotation, scale, duration = 1) =>
@currentRotation = rotation
@projection
.rotate(@currentRotation)
.scale(scale)
@groupPaths.selectAll("path")
.attr("d", path)
Run Code Online (Sandbox Code Playgroud)
为了理解为什么它这么慢,我在 Chrome 中做了一个配置文件记录,结果如下:

似乎 …
在通过发布请求调用的操作中,我创建资源调用并使用创建的资源作为参数RequestOffer发送电子邮件:ActionMailer
@request_offer = RequestOffer.new(request_offer_params)
if @request_offer.save
RequestOfferMailer.email_team(@request_offer).deliver_later
end
Run Code Online (Sandbox Code Playgroud)
当我的控制器规范时,我想测试是否使用以资源作为参数的RequestOfferMailer方法调用我的控制器。email_team@request_offer
当我想要 user 时expect(XXX).to receive(YYY).with(ZZZ),我发现的唯一方法是在发出 POST 请求之前声明我的期望。然而,ZZZ是由这个POST请求创建的,所以我之前没有办法设定我的期望。
# Set expectation first
message_delivery = instance_double(ActionMailer::MessageDelivery)
# ZZZ used in .with() does not exist yet, so it won't work
expect(RequestOfferMailer).to receive(:email_team).with(ZZZ).and_return(message_delivery)
expect(message_delivery).to receive(:deliver_later)
# Make POST request that will create ZZZ
post :create, params
Run Code Online (Sandbox Code Playgroud)
知道如何解决这个问题吗?