2013-04-22 30 views
1

更新:我已經將問題縮小到黃瓜軌道寶石做一些時髦。它工作到0.4.1版本,但除此之外,我得到了下面提到的錯誤。仍然不知道爲什麼。我已經完成了寶石的乾淨安裝,無濟於事。我的參數中的反斜槓

我遇到了包含無關內容的參數問題。

黃瓜測試提交一個表單,並有一個隱藏字段

<% if @collection.new_record? && current_user.pseuds.size > 1 %> 
    <dt><%= label_tag "owner_pseuds[]", ts("Owner Pseud(s):") %></dt> 
    <dd><%= select_tag "owner_pseuds[]", options_from_collection_for_select(current_user.pseuds, :id, :name, current_user.default_pseud), :multiple => true %></dd> 
<% else %> 
    <p><%= hidden_field_tag "owner_pseuds[]", [current_user.default_pseud.id] %></p> 
<% end %> 

當我使用「Rails.logger.debug它讓我發現,我的owner_pseud ID爲5。然而,當形式被貼了,它顯示如下。

Started POST "/collections" for 127.0.0.1 at 2013-04-22 05:01:57 +0100 
    Processing by CollectionsController#create as HTML 
    Parameters: {"utf8"=>"✓", "owner_pseuds"=>["[\"5\"]"], "collection"=>{"name"=>"collection1", ... 

而且我結束了:(訴1.3.1) 未能找到ID = 「5」(ActiveRecord的:: RecordNotFound)

我使用黃瓜軌理想跟蹤準和水豚(v1.1.4)。

這是我正在從事的分支:https://github.com/scottsds/otwarchive/compare/upgrade_capybara_1_1_4。謝謝你提供的所有幫助!

default_pseud returns:#< Pseud:0x0000000a224070>,這是正確的。

+0

什麼是'default_pseud'返回? – 2013-04-22 05:39:56

回答

1

你爲什麼在括號中指定你的僞ID?我認爲這是問題,因爲Rails試圖保留單字符串格式。

不括號試試這個,與理想跟蹤準-ID

<p><%= hidden_field_tag "owner_pseuds[]", current_user.default_pseud.id %></p> 

這假定default_pseud.id不會是一個數組,其中,從看你的代碼,我認爲是一個正確的假設。

1

您正在將[current_user.default_pseud.id]放入數組中。嘗試沒有括號,就像這樣:

<p><%= hidden_field_tag "owner_pseuds[]", current_user.default_pseud.id %></p> 

和currrent_user.default_pseud.id將被評估爲一個字符串,這似乎是你想要的。

+0

我仍然得到相同的錯誤。我應該注意到,這個特定的測試(work_create.feature)通過使用舊版本的cucumber-rails和水豚的master分支。我沒有改變實際的功能本身,並跟蹤回溯(https://gist.github.com/scottsds/5b6774b3aa2c84cabe91)我沒有看到任何錯誤。我也不能在應用程序的實時副本上的黃瓜測試之外重現此錯誤。 – 2013-04-22 04:56:37

+0

將owner_pseuds []更改爲owner_pseuds,並且您的current_user.default_pseud.id將作爲字符串而不是數組容器傳遞。 – fengolly 2013-04-22 05:27:19

+0

不幸的是,owner_pseuds必須是一個數組,因爲用戶有多個可能性。讓它作爲字符串傳入時會在嘗試使用.each時在create方法的後面導致錯誤。 – 2013-04-22 05:35:33