1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Added the possibility of passing nil to UrlHelper#link_to to use the link itself as the name

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@338 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2005-01-05 00:38:09 +00:00
parent f92ae75a23
commit efe0348486
4 changed files with 46 additions and 15 deletions

View file

@ -1,3 +1,8 @@
*SVN*
* Added the possibility of passing nil to UrlHelper#link_to to use the link itself as the name
*1.2.0* (January 4th, 2005)
* Added MemCacheStore for storing session data in Danga's MemCache system [Bob Cottrell]

View file

@ -130,15 +130,15 @@ module ActionController #:nodoc:
# The passed <tt>filters</tt> will be appended to the array of filters that's run _before_ actions
# on this controller are performed.
def append_before_filter(*filters, &block)
filters << block if block_given?
append_filter_to_chain("before", filters)
filters << block if block_given?
append_filter_to_chain("before", filters)
end
# The passed <tt>filters</tt> will be prepended to the array of filters that's run _before_ actions
# on this controller are performed.
def prepend_before_filter(*filters, &block)
filters << block if block_given?
prepend_filter_to_chain("before", filters)
filters << block if block_given?
prepend_filter_to_chain("before", filters)
end
# Short-hand for append_before_filter since that's the most common of the two.
@ -147,15 +147,15 @@ module ActionController #:nodoc:
# The passed <tt>filters</tt> will be appended to the array of filters that's run _after_ actions
# on this controller are performed.
def append_after_filter(*filters, &block)
filters << block if block_given?
append_filter_to_chain("after", filters)
filters << block if block_given?
append_filter_to_chain("after", filters)
end
# The passed <tt>filters</tt> will be prepended to the array of filters that's run _after_ actions
# on this controller are performed.
def prepend_after_filter(*filters, &block)
filters << block if block_given?
prepend_filter_to_chain("after", filters)
filters << block if block_given?
prepend_filter_to_chain("after", filters)
end
# Short-hand for append_after_filter since that's the most common of the two.

View file

@ -13,15 +13,18 @@ module ActionView
# Creates a link tag of the given +name+ using an URL created by the set of +options+. See the valid options in
# link:classes/ActionController/Base.html#M000021. It's also possible to pass a string instead of an options hash to
# get a link tag that just points without consideration. The html_options have a special feature for creating javascript
# confirm alerts where if you pass :confirm => 'Are you sure?', the link will be guarded with a JS popup asking that question.
# If the user accepts, the link is processed, otherwise not.
# get a link tag that just points without consideration. If nil is passed as a name, the link itself will become the name.
# The html_options have a special feature for creating javascript confirm alerts where if you pass :confirm => 'Are you sure?',
# the link will be guarded with a JS popup asking that question. If the user accepts, the link is processed, otherwise not.
def link_to(name, options = {}, html_options = {}, *parameters_for_method_reference)
convert_confirm_option_to_javascript!(html_options) unless html_options.nil?
if options.is_a?(String)
content_tag "a", name, (html_options || {}).merge({ "href" => options })
content_tag "a", name || options, (html_options || {}).merge({ "href" => options })
else
content_tag("a", name, (html_options || {}).merge({ "href" => url_for(options, *parameters_for_method_reference) }))
content_tag(
"a", name || url_for(options, *parameters_for_method_reference),
(html_options || {}).merge({ "href" => url_for(options, *parameters_for_method_reference) })
)
end
end

View file

@ -15,6 +15,24 @@ class FilterTest < Test::Unit::TestCase
end
end
class LimitedFilterController < ActionController::Base
before_filter :ensure_login, :for => :show
def show
render_text "ran action"
end
def show_without_filter
render_text "ran action without filter"
end
private
def ensure_login
@ran_filter ||= []
@ran_filter << "ensure_login"
end
end
class PrependingController < TestController
prepend_before_filter :wonderful_life
@ -125,6 +143,11 @@ class FilterTest < Test::Unit::TestCase
def test_running_filters_with_class
assert test_process(AuditController).template.assigns["was_audited"]
end
def test_running_limited_filters
assert_equal %w( fire_flash ensure_login ), test_process(LimitedFilterController, "show").template.assigns["ran_filter"]
assert_equal %w( fire_flash ), test_process(LimitedFilterController, "show_without_filter").template.assigns["ran_filter"]
end
def test_bad_filter
assert_raises(ActionController::ActionControllerError) {
@ -151,9 +174,9 @@ class FilterTest < Test::Unit::TestCase
end
private
def test_process(controller)
def test_process(controller, action = "show")
request = ActionController::TestRequest.new
request.action = "show"
request.action = action
controller.process(request, ActionController::TestResponse.new)
end
end