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

Ticket #1269: link_to_post.diff

File link_to_post.diff, 3.1 kB (added by nzkoz, 3 years ago)

The patch to implement as mentioned

  • actionpack/test/template/javascript_helper.rb

    old new  
    55 
    66  def test_escape_javascript 
    77    assert_equal %(This \\"thing\\" is really\\n netos\\'), escape_javascript(%(This "thing" is really\n netos')) 
     8  end  
     9  
     10  def test_link_to_post 
     11    expected = %(<form action="/blah" method="post"><a href="#" onclick="this.parentNode.submit(); return false;">test</a></form>) 
     12     
     13    assert_equal(expected, link_to_post("test", :controller=>"blah")) 
    814  end 
    915end 
  • actionpack/lib/action_view/helpers/javascript_helper.rb

    old new  
    121121        function = "#{function}; #{options[:after]}"  if options[:after] 
    122122        function = "if (#{options[:condition]}) { #{function}; }" if options[:condition] 
    123123        function = "if (confirm('#{escape_javascript(options[:confirm])}')) { #{function}; }" if options[:confirm] 
    124          
     124   
    125125        return function 
    126126      end 
    127127 
     128      def link_to_post(name, options={}, html_options = {}) 
     129        s = form_tag(options) 
     130        s << link_to_function(name, "this.parentNode.submit()", html_options) 
     131        s << "</form>" 
     132        return s 
     133      end 
     134 
     135 
    128136      # Includes the Action Pack Javascript library inside a single <script>  
    129137      # tag. 
    130138      # 
     
    182190        js_options['asynchronous'] = options[:type] != :synchronous 
    183191        js_options['method']       = options[:method] if options[:method] 
    184192        js_options['insertion']    = "Insertion.#{options[:position].to_s.camelize}" if options[:position] 
    185          
     193   
    186194        if options[:form] 
    187195          js_options['parameters'] = 'Form.serialize(this)' 
    188196        elsif options[:with] 
  • actionpack/lib/action_view/helpers/asset_tag_helper.rb

    old new  
    110110          source = "/#{dir}/#{source}" unless source.include?("/") 
    111111          source = "#{source}.#{ext}" unless source.include?(".") 
    112112          source = "#{@request.relative_url_root}#{source}" 
    113           @controller.asset_host + source 
     113          ActionController::Base.asset_host + source 
    114114        end 
    115115    end 
    116116  end