带有表单的Rails 4自定义帮助器方法在视图中不会得到输出 – 完全

我在application_helper.rb有这个,因为我对许多模型使用相同的filterforms。

 def filter_form(path, filter_options, button) form_tag(path, remote: true, method: "get") do label_tag(:filter, "Filter by") select_tag(:filter_type, options_for_select(filter_options)) "for:".html_safe text_field_tag(:filter) button_tag(:submit, "Submit") if button == true end end 

在我的用户文章中,例如我有

  

但是在代码中我可以看到它只生成

标签,这一切都很好,但没有任何表单元素出现。 这是为什么?

尝试使用concat

 def filter_form(path, filter_options, button) form_tag(path, remote: true, method: "get") do concat label_tag(:filter, "Filter by") concat select_tag(:filter_type, options_for_select(filter_options)) "for:".html_safe concat text_field_tag(:filter) concat button_tag(:submit, "Submit") if button == true end end 

这里有一篇好文章