带有表单的Rails 4自定义帮助器方法无法在视图中获得输出-完全 [英] Rails 4 custom helper method with form doesn't get output in view - fully

查看:80
本文介绍了带有表单的Rails 4自定义帮助器方法无法在视图中获得输出-完全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

application_helper.rb中有此选项,因为我对许多模型使用相同的过滤器形式.

I have this in application_helper.rb because I use the same filter form for a number of models.

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>标记,这很好,但是没有任何表单元素显示.为什么会这样?

However in the code I can see it only generates the <form action="/articles" accept-charset="UTF-8" data-remote="true" method="get"><input name="utf8" value="✓" type="hidden"></form> tag which is all fine and good but none of the form elements show up. Why is that?

推荐答案

尝试使用 concat

Try using 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自定义帮助器方法无法在视图中获得输出-完全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆