Changeset 7791
- Timestamp:
- 10/08/07 03:30:29 (2 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_view/helpers/url_helper.rb (modified) (2 diffs)
- trunk/actionpack/test/template/url_helper_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r7779 r7791 1 1 *SVN* 2 3 * Add link_to :back which uses your referrer with a fallback to a javascript link. #7366 [eventualbuddha, tarmo] 2 4 3 5 * error_messages_for and friends also work with local variables. #9699 [Frederick Cheung] trunk/actionpack/lib/action_view/helpers/url_helper.rb
r7668 r7791 87 87 # url_for. It's also possible to pass a string instead 88 88 # of an options hash to get a link tag that uses the value of the string as the 89 # href for the link. If nil is passed as a name, the link itself will become 90 # the name. 89 # href for the link, or use +:back+ to link to the referrer - a JavaScript back 90 # link will be used in place of a referrer if none exists. If nil is passed as 91 # a name, the link itself will become the name. 91 92 # 92 93 # ==== Options … … 135 136 # m.setAttribute('value', 'delete'); f.appendChild(m);f.submit(); };return false;">Delete Image</a> 136 137 def link_to(name, options = {}, html_options = nil) 137 url = options.is_a?(String) ? options : self.url_for(options) 138 url = case options 139 when String 140 options 141 when :back 142 @controller.request.env["HTTP_REFERER"] || 'javascript:history.back()' 143 else 144 self.url_for(options) 145 end 138 146 139 147 if html_options trunk/actionpack/test/template/url_helper_test.rb
r7668 r7791 1 1 require "#{File.dirname(__FILE__)}/../abstract_unit" 2 2 3 RequestMock = Struct.new("Request", :request_uri, :protocol, :host_with_port )3 RequestMock = Struct.new("Request", :request_uri, :protocol, :host_with_port, :env) 4 4 5 5 class UrlHelperTest < Test::Unit::TestCase … … 108 108 def test_link_tag_with_query_and_no_name 109 109 assert_dom_equal "<a href=\"http://www.example.com?q1=v1&q2=v2\">http://www.example.com?q1=v1&q2=v2</a>", link_to(nil, "http://www.example.com?q1=v1&q2=v2") 110 end 111 112 def test_link_tag_with_back 113 @controller.request = RequestMock.new("http://www.example.com/weblog/show", nil, nil, {'HTTP_REFERER' => 'http://www.example.com/referer'}) 114 assert_dom_equal "<a href=\"http://www.example.com/referer\">go back</a>", link_to('go back', :back) 115 end 116 117 def test_link_tag_with_back_and_no_referer 118 @controller.request = RequestMock.new("http://www.example.com/weblog/show", nil, nil, {}) 119 assert_dom_equal "<a href=\"javascript:history.back()\">go back</a>", link_to('go back', :back) 110 120 end 111 121