Skip to content
This repository
Browse code

Added the option of passing a block to ActiveRecordHelper#form in ord…

…er 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
  • Loading branch information...
commit c81af992e84169e7e462a99dd1f86b96eff7d345 1 parent 31901a5
David Heinemeier Hansson authored January 15, 2005
7  actionpack/CHANGELOG
... ...
@@ -1,5 +1,12 @@
1 1
 *SVN*
2 2
 
  3
+* Added the option of passing a block to ActiveRecordHelper#form in order to add more to the auto-generated form #469 [dom@sisna.com]
  4
+
  5
+    form("entry", :action => "sign") do |form|
  6
+      form << content_tag("b", "Department")
  7
+      form << collection_select("department", "id", @departments, "id", "name")
  8
+    end
  9
+
3 10
 * Added arrays as a value option for params in url_for and friends #467 [Eric Anderson]. Example:
4 11
 
5 12
     url_for(:controller => 'user', :action => 'delete', :params => { 'username' =>  %( paul john steve ) } )
13  actionpack/lib/action_view/helpers/active_record_helper.rb
@@ -49,6 +49,13 @@ def input(record_name, method)
49 49
       #       <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /><br />
50 50
       #       <input type='submit' value='Sign' />
51 51
       #     </form>
  52
+      #
  53
+      # It's also possible to add additional content to the form by giving it a block, such as:
  54
+      #
  55
+      #   form("entry", :action => "sign") do |form|
  56
+      #     form << content_tag("b", "Department")
  57
+      #     form << collection_select("department", "id", @departments, "id", "name")
  58
+      #   end
52 59
       def form(record_name, options = {})
53 60
         record   = instance_eval("@#{record_name}")
54 61
 
@@ -59,9 +66,9 @@ def form(record_name, options = {})
59 66
         
60 67
         id_field = record.new_record? ? "" : InstanceTag.new(record_name, "id", self).to_input_field_tag("hidden")
61 68
         
62  
-        %(<form action="#{action}" method="post">#{id_field}) +
63  
-          all_input_tags(record, record_name, options) +
64  
-          %(<input type="submit" value="#{submit_value}" /></form>)
  69
+        formtag = %(<form action="#{action}" method="post">#{id_field}) + all_input_tags(record, record_name, options)
  70
+        yield formtag if block_given?
  71
+        formtag +  %(<input type="submit" value="#{submit_value}" /></form>)
65 72
       end
66 73
 
67 74
       # Returns a string containing the error message attached to the +method+ on the +object+, if one exists.
3  actionpack/lib/action_view/helpers/form_options_helper.rb
@@ -4,8 +4,7 @@
4 4
 
5 5
 module ActionView
6 6
   module Helpers
7  
-    # Provides a number of methods for turning different kinds of containers into a set of option tags. Neither of the methods provide
8  
-    # the actual select tag, so you'll need to construct that in HTML manually.
  7
+    # Provides a number of methods for turning different kinds of containers into a set of option tags.
9 8
     module FormOptionsHelper
10 9
       include ERB::Util
11 10
 

0 notes on commit c81af99

Please sign in to comment.
Something went wrong with that request. Please try again.