我有一个诊断规范,我相信我在规范和视图文件之间使用该语言存在一些不一致。但是我无法解决问题。测试如下
it "updates a diagnostic report" do
diagnostic_info = FG.create(:diagnostic_info)
diagnostic_info.save!
visit edit_admin_diagnostic_path(diagnostic_info)
fill_in 'diagnostic_info_notes', with: "test notes"
click_button "Save"
page.should have_content("Saved")
page.should have_content("test notes")
端
视图是
.field
= label_tag :notes
= f.text_field "notes"
= submit_tag @diagnostic.data["Save"], method: :put, data: { confirm: "Are you sure?" }
,失败是
1) /admin/diagnostics updates a diagnostic report
Failure/Error: click_button "Save"
Capybara::ElementNotFound:
Unable to find button "Save"
我一直在尝试更改视图文件中的语法,以便提交标记代替一个按钮。这是因为我认为问题是使用标签而不是按钮。但是我无法成功地使用haml语法。
答案 0 :(得分:0)
Rails有built in support用于本地化和国际化。无需自己动手。
# app/views/diagnostics/edit.haml.erb
.field
= label_tag :notes
= f.text_field "notes"
= submit_tag I18n.t('.save'), method: :put, data: { confirm: "Are you sure?" }
翻译存储在config/locales
。
# config/locales/en.yml
en:
diagnostics:
edit:
save: 'Save'
您也可以在规范中使用您的翻译:
it "updates a diagnostic report" do
diagnostic_info = FG.create(:diagnostic_info)
diagnostic_info.save!
visit edit_admin_diagnostic_path(diagnostic_info)
fill_in 'diagnostic_info_notes', with: "test notes"
click_button I18n.t('diagnostics.edit.save') # Note that we need full path
page.should have_content(I18n.t('diagnostics.edit.save'))
page.should have_content("test notes")
end