我想在那里使用yml文件中声明的变量.例如,我声明site_name并想在下面使用它description.
en:
site_name: &site_name "Site Name"
static_pages:
company:
description: *site_name #this works fine
description: "#{*site_name} is an online system" #this doesn't work
Run Code Online (Sandbox Code Playgroud)
如何将*site_name变量与其他文本组合在一起?
我有一个阵列
@words = Word.find_all_by_lesson_id(params[:id]) - @user.words
Run Code Online (Sandbox Code Playgroud)
并希望通过word_id找到一个元素,例如
@current_word = @words[params[:id2].to_i]
Run Code Online (Sandbox Code Playgroud)
这里
params[:id2]是words.id
当然这是错误的,因为数组索引不一样words.id,所以我怎么能正确呢?
要么
如果我想从中排除一些记录,你能告诉我如何使用该模型吗?
我不明白如何使用rspec和国际化进行测试.例如,在我做的请求测试中
I18n.available_locales.each do |locale|
visit users_path(locale: locale)
#...
end
Run Code Online (Sandbox Code Playgroud)
它工作得很好:每个语言环境测试都是正确的.
但在邮寄者中,这个技巧不起作用.
user_mailer_spec.rb
require "spec_helper"
describe UserMailer do
I18n.available_locales.each do |locale|
let(:user) { FactoryGirl.build(:user, locale: locale.to_s) }
let(:mail_registration) { UserMailer.registration_confirmation(user) }
it "should send registration confirmation" do
puts locale.to_yaml
mail_registration.body.encoded.should include("test") # it will return error with text which allow me to ensure that for each locale the test call only :en locale email template
end
end
end
Run Code Online (Sandbox Code Playgroud)
它运行几次(我有多少语言环境),但每次只生成默认语言环境的html.
当我UserMailer.registration_confirmation(@user).deliver从控制器打电话时,它工作正常.
user_mailer.rb
...
def registration_confirmation(user)
@user = user
mail(to: user.email, …Run Code Online (Sandbox Code Playgroud) rspec ruby-on-rails actionmailer internationalization ruby-on-rails-3