我正在使用Ruby on Rails生成电子邮件.如电子邮件标记文档中所述,我修改了我的(*.html.haml)模板以包含电子邮件标记的模式.下面的代码来自我的邮件模板:
%script{ type: "application/ld+json" }
{
"@context" : "http://schema.org",
"@type" : "FoodEstablishmentReservation",
"reservationNumber" : "#{reservation.id}",
...
}
Run Code Online (Sandbox Code Playgroud)
我还将电子邮件的发件人和收件人修改为此处提到的用于在开发模式下测试架构的相同电子邮件ID .
当我在Gmail收件箱中收到电子邮件时,我发现之前没有任何不同之处.当我查看电子邮件的原始消息时,它显示:
Return-Path: <breezebhoewal@gmail.com>
...
Date: Wed, 21 Dec 2016 13:14:45 +0530
From: breezebhoewal@gmail.com
To: breezebhoewal@gmail.com
...
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="--==_mimepart_585a32ecf2d94_143673fd10d24128893014"; charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_585a32ecf2d94_143673fd10d24128893014
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
...
<script type=3D'application/ld+json'>
{
"@context" : "http://schema.org",
"@type" : "FoodEstablishmentReservation",
"reservationNumber" : "<reservation-id>",
...
}
</script>
...
Run Code Online (Sandbox Code Playgroud)
现在,如果我<script>在电子邮件标记测试程序中 …
我有一个Hash,我想在深层插入一些数据,但任何级别的密钥都可能丢失.所以,我在每个级别更新它的值之前有条件地初始化它.
什么是更好的方式来编写这个或一种可以使代码不那么难看的方法?
data[:foo] ||= {}
data[:foo][:bar] ||= {}
data[:foo][:bar][:baz] ||= []
data[:foo][:bar][:baz] << 99
Run Code Online (Sandbox Code Playgroud) 我有一个代码如下:
secret_number = 8
user_input = ""
def number_guesser(user_input)
while user_input != secret_number
puts "Guess a number between 1 and 10:"
user_input = gets.chomp
if user_input != secret_number
puts "Wrong! Try again."
else
puts "You guessed correctly!"
end
end
end
number_guesser(user_input)
Run Code Online (Sandbox Code Playgroud)
当我试图运行上面的程序时,它显示如下:
****未定义的局部变量或方法secret_number' for main:Object
(repl):211:innumber_guesser'(repl):221:在''****
有任何想法吗?
我想用capybara用rspec.
的Gemfile
group :test do
gem 'capybara'
end
Run Code Online (Sandbox Code Playgroud)
根据文档,我需要添加require 'capybara/rspec'到rails_helper.rb,我做了:
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'
require 'capybara/rspec'
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
config.filter_rails_from_backtrace!
end
Run Code Online (Sandbox Code Playgroud)
现在,当我跑bundle exec rspec.我得到:
Failure/Error: visit('/')
NoMethodError:
undefined method `visit' for #<RSpec::ExampleGroups::HomeFooters:0x000000035cc4b8>
Run Code Online (Sandbox Code Playgroud)
测试如下:
require 'rails_helper'
RSpec.describe "HomeFooters", type: :request do
it "show proper links in footer" …Run Code Online (Sandbox Code Playgroud)