我正在使用sinatra,我想使用嵌入式1-1
实现嵌入文档这是我的主要收藏品,只嵌入一个环境 TestSuite类 包括Mongoid :: Document
field :testSuiteName
field :introduction
field :itemsToTest
field :dateCreation
attr_accessible :testSuiteName,:introduction,:itemsToTest,:dateCreation
embeds_one :environment
embeds_many :steps
end
每个TestSuite都嵌入了许多步骤
class Step
include Mongoid::Document
field :stepRole
field :stepOrderNum
embedded_in :testSuite
embedded_in :environment
has_one :function
end
运行testSuite我必须设置嵌入许多步骤的测试环境
class Environment
include Mongoid::Document
embedded_in :testSuite
embeds_many :steps
end
get '/createTestSuite' do
name=params[:testName]
intro=params[:introduction]
items=['data','shemas']
test1=TestSuite.create()
test1.testSuiteName="firstOne"
test1. introduction="my first Test Suite"
test1.itemsToTest=["data","shemas"]
test1. dateCreation="23/01/214 18:18"
test1.environment.create()
test1.environment.steps.create(stepRole: "inserer donneés",stepOrderNum: "2")
问题:
NoMethodError - undefined method `create' for nil:NilClass:
C:/Users/mohamedamine.sakhri/Documents/Aptana Studio 3 Workspace/zProject/main.rb:99:in `block in <main>'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `block in compile!'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `[]'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (3 levels) in route!'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:985:in `route_eval'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (2 levels) in route!'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1006:in `block in process_route'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `catch'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `process_route'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:964:in `block in route!'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `each'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `route!'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1076:in `block in dispatch!'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1073:in `dispatch!'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `block in call!'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `call!'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:886:in `call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/logger.rb:15:in `call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/commonlogger.rb:33:in `call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:217:in `call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:210:in `call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/show_exceptions.rb:21:in `call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:180:in `call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:2014:in `call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `block in call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1788:in `synchronize'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
c:/Ruby200/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
c:/Ruby200/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
c:/Ruby200/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
如何在嵌入环境文档的情况下创建testSuite?