简体   繁体   English

为什么Rails form_tag显示数组?

[英]Why is a Rails form_tag displaying an array?

Using Rails 3/Ruby 1.9.3, I have to dynamically generate a form using an array of values. 使用Rails 3 / Ruby 1.9.3,我必须使用值数组动态生成表单。 The form generates properly with the exception that the @sub_fields array is being output to the screen between the form values and the submit button. 表单正确生成,但@sub_fields数组正在输出到表单值和提交按钮之间的屏幕。

The HAML code that generates the form looks like this: 生成表单的HAML代码如下所示:

= form_tag "/magazine/subscribers" do
  = @sub_fields.each do |k,v|
    .formField
      - if v.has_key? :evaluate
        = label_tag k.to_s, v[:label_text]
        = v[:evaluate].call(k)
      - else
        - unless v[:input_type] == :hidden_field
          = label_tag k, v[:label_text]
        - if v[:select_options]
          = select_tag(k, options_for_select(v[:select_options].call))
        - else
          = eval(v[:input_type].to_s + "_tag '#{v[:value].to_s}'")
      - if v.has_key? :tooltip
        .fieldTip
          %ul
            - v[:tooltip].each do |tip|
              %li= tip

  .formAction
    = submit_tag "localize edit"

使用-代替=

- @sub_fields.each do |k,v|

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM