streamlined_form_builder.rb

来自「ruby on rails web敏捷开发之路第二版 源代码」· RB 代码 · 共 37 行

RB
37
字号
#---# Excerpted from "Agile Web Development with Rails, 2nd Ed."# We make no guarantees that this code is fit for any purpose. # Visit http://www.pragmaticprogrammer.com/titles/rails2 for more book information.#---module Streamlined  class TabularFormBuilder < ActionView::Helpers::FormBuilder    (field_helpers - %w(hidden_field)).each do |selector|      src = <<-END_SRC        def #{selector}(field, *args, &proc)          "<tr>" +            "<td><label for='\#{field}'>\#{field.to_s.humanize}:</label></td>" +            "<td>" + super + "</td>" +          "</tr>"        end      END_SRC      class_eval src, __FILE__, __LINE__    end    def submit_tag(value)      "<tr>"+        "<td>&nbsp;</td>"+        "<td><input name='commit' type='submit' value='#{value}'/></td>"+      "</tr>"    end  end  module FormHelpers    def streamlined_form_for(name, object, options, &proc)      concat("<table>", proc.binding)      form_for(name, object, options.merge(:builder => TabularFormBuilder), &proc)      concat("</table>", proc.binding)    end  endendActionView::Base.class_eval do  include Streamlined::FormHelpersend

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?