Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 带cocoon的水豚形值集_Ruby On Rails_Ruby On Rails 4_Nested Attributes_Cocoon Gem - Fatal编程技术网

Ruby on rails 带cocoon的水豚形值集

Ruby on rails 带cocoon的水豚形值集,ruby-on-rails,ruby-on-rails-4,nested-attributes,cocoon-gem,Ruby On Rails,Ruby On Rails 4,Nested Attributes,Cocoon Gem,我正在尝试使用Cocoon和rails 4为具有嵌套属性的表单编写测试。问题是我找不到要设置的表单元素 我尝试了以下注释掉的变体,但找不到get元素: click_link('Add Owner') # should display the fields #fill_in 'First Name', with: "sean" #find("input#horse_owner_attributes_fname").set('sean') #find(:xpath, '//input[@id="h

我正在尝试使用Cocoon和rails 4为具有嵌套属性的表单编写测试。问题是我找不到要设置的表单元素

我尝试了以下注释掉的变体,但找不到get元素:

click_link('Add Owner') # should display the fields

#fill_in 'First Name', with: "sean"
#find("input#horse_owner_attributes_fname").set('sean')
#find(:xpath, '//input[@id="horse_owner_attributes_lname"]').set("sean")
我不确定我的问题是cocoon“link_to_add_association”的动态特性,还是我不知道如何使用find,或者其他原因

我的主要表格是:

#owner
  #owner_from_list
    = f.collection_select(:owner_id, @owners, :id,  :fname, { :prompt => "Existing Owner" }, {:class => 'form-control'} ) # shows drop down of existing records

= link_to_add_association 'Add Owner', f, :owner, :class => "btn btn-default btn-sm", :data => {"association-insertion-method" => "after" } # to add a new record
和我的添加所有者部分:

= f.inputs do
  .nested-fields
    = f.input :fname, :as => :string, label: "First Name", hint: "Owner's first name REQUIRED", :required => true  
    = f.input :lname, :as => :string, label: "Last Name", hint: "Last name REQUIRED", :required => true  

这看起来像是我遇到的问题

如果您想填写在单击Cocoon链接后动态添加的字段,您应该将
js:true
作为选项传递给相关场景

你可以看到我的问题和克里斯·彼得斯给我的完美答案: 想知道更多的信息