Changeset 8626
- Timestamp:
- 01/11/08 16:25:23 (6 months ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_view/helpers/active_record_helper.rb (modified) (2 diffs)
- trunk/actionpack/test/template/active_record_helper_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r8625 r8626 1 1 *SVN* 2 3 * Fixed ActionView::Helpers::ActiveRecordHelper::form for when protect_from_forgery is used #10739 [jeremyevans] 2 4 3 5 * Provide nicer access to HTTP Headers. Instead of request.env["HTTP_REFERRER"] you can now use request.headers["Referrer"]. [Koz] trunk/actionpack/lib/action_view/helpers/active_record_helper.rb
r8466 r8626 57 57 # form << collection_select("department", "id", @departments, "id", "name") 58 58 # end 59 # 60 # The following options are available: 61 # 62 # * <tt>action</tt> - the action used when submitting the form (default: create if a new record, otherwise update) 63 # * <tt>input_block</tt> - specialize the output using a different block, see above 64 # * <tt>method</tt> - the method used when submitting the form (default: post) 65 # * <tt>multipart</tt> - whether to change the enctype of the form to multipart/form-date, used when uploading a file (default: false) 66 # * <tt>submit_value</tt> - the text of the submit button (default: Create if a new record, otherwise Update) 59 67 def form(record_name, options = {}) 60 68 record = instance_variable_get("@#{record_name}") … … 66 74 submit_value = options[:submit_value] || options[:action].gsub(/[^\w]/, '').capitalize 67 75 68 contents = ''76 contents = form_tag({:action => action}, :method =>(options[:method] || 'post'), :enctype => options[:multipart] ? 'multipart/form-data': nil) 69 77 contents << hidden_field(record_name, :id) unless record.new_record? 70 78 contents << all_input_tags(record, record_name, options) 71 79 yield contents if block_given? 72 80 contents << submit_tag(submit_value) 73 74 content_tag('form', contents, :action => action, :method => 'post', :enctype => options[:multipart] ? 'multipart/form-data': nil) 81 contents << '</form>' 75 82 end 76 83 trunk/actionpack/test/template/active_record_helper_test.rb
r8564 r8626 87 87 @user.email = "" 88 88 end 89 90 def protect_against_forgery? 91 @protect_against_forgery ? true : false 92 end 93 attr_accessor :request_forgery_protection_token, :form_authenticity_token 89 94 90 95 def setup … … 141 146 ) 142 147 end 148 149 def test_form_with_protect_against_forgery 150 @protect_against_forgery = true 151 @request_forgery_protection_token = 'authenticity_token' 152 @form_authenticity_token = '123' 153 assert_dom_equal( 154 %(<form action="create" method="post"><div style='margin:0;padding:0'><input type='hidden' name='authenticity_token' value='123' /></div><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>), 155 form("post") 156 ) 157 end 158 159 def test_form_with_method_option 160 assert_dom_equal( 161 %(<form action="create" method="get"><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>), 162 form("post", :method=>'get') 163 ) 164 end 143 165 144 166 def test_form_with_action_option