From c81af992e84169e7e462a99dd1f86b96eff7d345 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 15 Jan 2005 18:57:17 +0000 Subject: [PATCH] Added the option of passing a block to ActiveRecordHelper#form in order to add more to the auto-generated form #469 [dom@sisna.com] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@422 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 7 +++++++ .../lib/action_view/helpers/active_record_helper.rb | 13 ++++++++++--- .../lib/action_view/helpers/form_options_helper.rb | 3 +-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 69075f04db6..426a8430c5b 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,12 @@ *SVN* +* Added the option of passing a block to ActiveRecordHelper#form in order to add more to the auto-generated form #469 [dom@sisna.com] + + form("entry", :action => "sign") do |form| + form << content_tag("b", "Department") + form << collection_select("department", "id", @departments, "id", "name") + end + * Added arrays as a value option for params in url_for and friends #467 [Eric Anderson]. Example: url_for(:controller => 'user', :action => 'delete', :params => { 'username' => %( paul john steve ) } ) diff --git a/actionpack/lib/action_view/helpers/active_record_helper.rb b/actionpack/lib/action_view/helpers/active_record_helper.rb index 6855fa49c53..82c6d1cd81f 100644 --- a/actionpack/lib/action_view/helpers/active_record_helper.rb +++ b/actionpack/lib/action_view/helpers/active_record_helper.rb @@ -49,6 +49,13 @@ module ActionView #
# # + # + # It's also possible to add additional content to the form by giving it a block, such as: + # + # form("entry", :action => "sign") do |form| + # form << content_tag("b", "Department") + # form << collection_select("department", "id", @departments, "id", "name") + # end def form(record_name, options = {}) record = instance_eval("@#{record_name}") @@ -59,9 +66,9 @@ module ActionView id_field = record.new_record? ? "" : InstanceTag.new(record_name, "id", self).to_input_field_tag("hidden") - %(
#{id_field}) + - all_input_tags(record, record_name, options) + - %(
) + formtag = %(
#{id_field}) + all_input_tags(record, record_name, options) + yield formtag if block_given? + formtag + %(
) end # Returns a string containing the error message attached to the +method+ on the +object+, if one exists. diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index 4205903b8f1..4f0a0fbfe0e 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -4,8 +4,7 @@ require File.dirname(__FILE__) + '/form_helper' module ActionView module Helpers - # Provides a number of methods for turning different kinds of containers into a set of option tags. Neither of the methods provide - # the actual select tag, so you'll need to construct that in HTML manually. + # Provides a number of methods for turning different kinds of containers into a set of option tags. module FormOptionsHelper include ERB::Util