2017-04-27 54 views
0

我與水豚嘗試使用Select Method。我嘗試了所有解決方案,尤其是那些來自Stackoverflow Discussion的解決方案。水豚select_option被發現,但沒有選擇

我有以下選擇,country_select寶石。這是從形式html.erb代碼:

<%= f.country_select(:country, {include_blank: 'Select a country', selected: "Select a country"}, {class: 'form-control', :id => "country_select"}) %> 

從瀏覽器的HTML看起來像這樣:

<select class="form-control" id="country_select" name="user[country]"><option value="">Select a country</option> 
    <option value="AF">Afghanistan</option> 
    <option value="AX">Åland Islands</option> 
    <option value="AL">Albania</option> 
    other staff... 

當調試從水豚GEM file actions.rb row 183(這裏我設置的選擇方法斷點),輸出是正確的。

def select(value, options={}) 
    binding.pry 
    if options.has_key?(:from) 
     from = options.delete(:from) 
     find(:select, from, options).find(:option, value, options).select_option 
    else 
     find(:option, value, options).select_option 
    end 
    end 

因此該行:

find(:select, from, options).find(:option, value, options) 

回報

=> #<Capybara::Node::Element tag="option" path="/html/body/div/div[2]/div/div/div/div/div/form/div[4]/select/option[2]"> 

這是正確的選擇選項。正如你所看到的option[2]是阿富汗,但它看起來像.select_option不起作用。

我覺得水豚選擇前場是不開放的選擇框。 我有水豚(2.13.0)和軌道5.0.2

非常感謝 法布里奇奧Bertoglio

回答