Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 4374

Show
Ignore:
Timestamp:
05/28/06 23:39:37 (2 years ago)
Author:
david
Message:

Added :method handling for other verbs to remote_form_tag and remote_form_for [DHH]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r4371 r4374  
    11*SVN* 
     2 
     3* Added :method handling for other verbs to remote_form_tag and remote_form_for [DHH] 
    24 
    35* Expanded :method option in FormHelper#form_tag to allow for verbs other than GET and POST by automatically creating a hidden form field named _method, which will simulate the other verbs over post [DHH] 
  • trunk/actionpack/lib/action_view/helpers/form_tag_helper.rb

    r4371 r4374  
    2121        html_options = options.stringify_keys 
    2222        html_options["enctype"] = "multipart/form-data" if html_options.delete("multipart") 
    23         html_options["action"] = url_for(url_for_options, *parameters_for_url) 
    24          
     23        html_options["action"] = url_for(url_for_options, *parameters_for_url) 
     24 
    2525        method_tag = "" 
    2626         
  • trunk/actionpack/lib/action_view/helpers/prototype_helper.rb

    r4268 r4374  
    165165        options[:html] ||= {} 
    166166        options[:html][:onsubmit] = "#{remote_function(options)}; return false;" 
    167         options[:html][:action] = options[:html][:action] || url_for(options[:url]) 
    168         options[:html][:method] = options[:html][:method] || "post" 
    169  
    170         tag("form", options[:html], true) 
     167 
     168        form_tag(options[:html].delete(:action) || url_for(options[:url]), options[:html]) 
    171169      end 
    172170 
  • trunk/actionpack/lib/action_view/helpers/url_helper.rb

    r4370 r4374  
    2525          escape = true 
    2626        end 
     27 
    2728        url = @controller.send(:url_for, options, *parameters_for_method_reference) 
    2829        escape ? html_escape(url) : url 
     
    5859          tag_options = nil 
    5960        end 
     61 
    6062        url = options.is_a?(String) ? options : self.url_for(options, *parameters_for_method_reference) 
    6163        "<a href=\"#{url}\"#{tag_options}>#{name || url}</a>" 
  • trunk/actionpack/test/template/prototype_helper_test.rb

    r4014 r4374  
    99  include ActionView::Helpers::TagHelper 
    1010  include ActionView::Helpers::TextHelper 
     11  include ActionView::Helpers::FormTagHelper 
    1112  include ActionView::Helpers::FormHelper 
    1213  include ActionView::Helpers::CaptureHelper 
     
    1516    @controller = Class.new do 
    1617      def url_for(options, *parameters_for_method_reference) 
    17         url =  "http://www.example.com/" 
    18         url << options[:action].to_s if options and options[:action] 
    19         url << "?a=#{options[:a]}" if options && options[:a] 
    20         url << "&b=#{options[:b]}" if options && options[:a] && options[:b] 
    21         url 
     18        if options.is_a?(String) 
     19          options 
     20        else 
     21          url =  "http://www.example.com/" 
     22          url << options[:action].to_s if options and options[:action] 
     23          url << "?a=#{options[:a]}" if options && options[:a] 
     24          url << "&b=#{options[:b]}" if options && options[:a] && options[:b] 
     25          url 
     26        end 
    2227      end 
    2328    end.new 
     
    6166    assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({success:'glass_of_beer',failure:'glass_of_water'}, 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">), 
    6267      form_remote_tag(:update => { :success => 'glass_of_beer', :failure => "glass_of_water" }, :url => { :action => :fast  }) 
     68  end 
     69 
     70  def test_form_remote_tag_with_method 
     71    assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\"><input name='_method' type='hidden' value='put' />), 
     72      form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast  }, :html => { :method => :put }) 
    6373  end 
    6474