我得到了带有多个复选框的simple_form,它们在模型中保存了带有某些方法名称的数组。表单如下:
<%= simple_form_for @testrun do |f| %>
<%= f.input :testcase, as: :check_boxes,
collection: [["test1", :test1], ["test2", :test2]] %>
<%= f.submit %>
<% end %>
我在控制器中的创建方法如下:
def create
@testrun = Testrun.new(testrun_params)
if @testrun.save
Testrun.delay.process!(@testrun.id)
redirect_to @testrun, notice: 'Test run was successfully created.'
else
render :new
end
end
在我的模型中,我有方法process!
,我需要在数组中运行方法。
def process!
.
.
.
@test = Case.new(self)
@testrun[:testcase].each do |testcase|
@test.send testcase
end
end
启动过程时,出现错误NoMethodError: undefined method '[]' for nil:NilClass
我错在哪里?