From 5d1a305f066daf5a60b2b1158d5d2aeae6fe32cb Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 11 Jan 2008 16:25:23 +0000 Subject: Fixed ActionView::Helpers::ActiveRecordHelper::form for when protect_from_forgery is used (closes #10739) [jeremyevans] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8626 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_view/helpers/active_record_helper.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_view/helpers/active_record_helper.rb') diff --git a/actionpack/lib/action_view/helpers/active_record_helper.rb b/actionpack/lib/action_view/helpers/active_record_helper.rb index 9736b7e438..170ad84e43 100644 --- a/actionpack/lib/action_view/helpers/active_record_helper.rb +++ b/actionpack/lib/action_view/helpers/active_record_helper.rb @@ -56,6 +56,14 @@ module ActionView # form << content_tag("b", "Department") # form << collection_select("department", "id", @departments, "id", "name") # end + # + # The following options are available: + # + # * action - the action used when submitting the form (default: create if a new record, otherwise update) + # * input_block - specialize the output using a different block, see above + # * method - the method used when submitting the form (default: post) + # * multipart - whether to change the enctype of the form to multipart/form-date, used when uploading a file (default: false) + # * submit_value - the text of the submit button (default: Create if a new record, otherwise Update) def form(record_name, options = {}) record = instance_variable_get("@#{record_name}") @@ -65,13 +73,12 @@ module ActionView submit_value = options[:submit_value] || options[:action].gsub(/[^\w]/, '').capitalize - contents = '' + contents = form_tag({:action => action}, :method =>(options[:method] || 'post'), :enctype => options[:multipart] ? 'multipart/form-data': nil) contents << hidden_field(record_name, :id) unless record.new_record? contents << all_input_tags(record, record_name, options) yield contents if block_given? contents << submit_tag(submit_value) - - content_tag('form', contents, :action => action, :method => 'post', :enctype => options[:multipart] ? 'multipart/form-data': nil) + contents << '' end # Returns a string containing the error message attached to the +method+ on the +object+ if one exists. -- cgit v1.2.3