0

以下代码应该创建一个数组并将其作为参数哈希的一部分发送:

        it "should create an outing" do 
            lambda do 
                post :create, { :outing => FactoryGirl.attributes_for(:outing), :guestvalue => ["80","89"] , :barvalue => ["2976","2973"] }
            end.should change(Outing, :count).by(1)
        end 

相反,它给了我错误:

 NoMethodError:
   undefined method `[]' for nil:NilClass

参数被传递到我的控制器的这一部分:

    params[:guestvalue].each do |guest_id|
        @outing.add_guest(guest_id)
    end 

    params[:barvalue].each do |bar_id|
        @outing.add_bar(bar_id)
    end 
4

1 回答 1

0

对于仍然感兴趣的任何人,以下是传递数组的正确语法:

post :create, { :outing => FactoryGirl.attributes_for(:outing), :guestvalue => ["80","89"] , :barvalue => ["2976","2973"] }
于 2012-07-11T17:42:34.420 回答