2009-02-18 49 views
2

我得到在我的測試::單位輸出此警告...如何解決生產此警告,當我跑我的Test ::單元測試

/usr/local/bin/ruby -I.:lib:test -rtest/unit -e "%w[test/functional/sessions_controller_test.rb].each { |f| require f }" | unit_diff -u 
Loaded suite -e 
Started 
.../Users/ethan/project/mtc/contactdb/app/views/sessions/new.html.haml:30: warning: multiple values for a block parameter (0 for 1) 
    from /usr/local/lib/ruby/gems/1.8/gems/haml-2.0.8/lib/haml/helpers/action_view_mods.rb:142 
[...repeated eight times...] 

我認爲相關的部分是:

/contactdb/app/views/sessions/new.html.haml:30: warning: 
    multiple values for a block parameter (0 for 1) 

看着我Haml的文件,我已經將範圍縮小到這個片段(我認爲)...

- form_tag(recover_login_path, :method => 'get') do |f| 
    %p 
    = text_field_tag :email, '', { :size => '35', :maxlength => '255' } 

recover_login是一個名爲路線。

我查看了form_tag的API文檔。看起來我的代碼似乎是遵循他們在示例中的內容。

回答

5

form_tag塊不帶參數。所以刪除|f|,警告應該消失。

+0

正確的解決方案,但出於錯誤的原因。另一個迴應是技術上正確的。 – Fotios 2011-09-14 15:06:00

6

form_tag只有在窗體構建器對象|f|中使用模型對象時纔會傳遞它。

form_tag @user, :method => :get do |f| 
    f.text_field :first_name 
end 

,但沒有在模型對象通過,該塊參數沒有通過或用於構建自己的表單路徑。

form_tag user_path(@user.id), :method => :get do 
    text_field :user, :first_name 
end