导轨和形式4定制的helper方法没有得到鉴于输出 - 充分(Rails 4 custom help

2019-10-24 06:48发布

我有这个在application_helper.rb ,因为我用的是相同的过滤器形式的一些车型。

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))
      "<span>for:</span>".html_safe
      text_field_tag(:filter)
      button_tag(:submit, "Submit") if button == true
    end
  end

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

<%= filter_form(articles_path, @filter_options, false) %>

然而,在代码我可以看到它仅产生<form action="/articles" accept-charset="UTF-8" data-remote="true" method="get"><input name="utf8" value="✓" type="hidden"></form>标记这是所有微细且良好的,但没有表单元素的显示。 这是为什么?

Answer 1:

尝试使用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))
     "<span>for:</span>".html_safe
     concat text_field_tag(:filter)
     concat button_tag(:submit, "Submit") if button == true
   end
end

这是一个很好的文章在这里



文章来源: Rails 4 custom helper method with form doesn't get output in view - fully