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
This commit is contained in:
David Heinemeier Hansson 2005-01-15 18:57:17 +00:00
parent 31901a5939
commit c81af992e8
3 changed files with 18 additions and 5 deletions

View File

@ -1,5 +1,12 @@
*SVN* *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: * 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 ) } ) url_for(:controller => 'user', :action => 'delete', :params => { 'username' => %( paul john steve ) } )

View File

@ -49,6 +49,13 @@ module ActionView
# <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /><br /> # <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /><br />
# <input type='submit' value='Sign' /> # <input type='submit' value='Sign' />
# </form> # </form>
#
# 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 = {}) def form(record_name, options = {})
record = instance_eval("@#{record_name}") 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 = record.new_record? ? "" : InstanceTag.new(record_name, "id", self).to_input_field_tag("hidden")
%(<form action="#{action}" method="post">#{id_field}) + formtag = %(<form action="#{action}" method="post">#{id_field}) + all_input_tags(record, record_name, options)
all_input_tags(record, record_name, options) + yield formtag if block_given?
%(<input type="submit" value="#{submit_value}" /></form>) formtag + %(<input type="submit" value="#{submit_value}" /></form>)
end end
# Returns a string containing the error message attached to the +method+ on the +object+, if one exists. # Returns a string containing the error message attached to the +method+ on the +object+, if one exists.

View File

@ -4,8 +4,7 @@ require File.dirname(__FILE__) + '/form_helper'
module ActionView module ActionView
module Helpers module Helpers
# Provides a number of methods for turning different kinds of containers into a set of option tags. Neither of the methods provide # Provides a number of methods for turning different kinds of containers into a set of option tags.
# the actual select tag, so you'll need to construct that in HTML manually.
module FormOptionsHelper module FormOptionsHelper
include ERB::Util include ERB::Util