Permalink
Browse files

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
  • Loading branch information...
1 parent f92ae75 commit efe0348486aee9b19877e730a6a07db9c717f2f2 @dhh dhh committed Jan 5, 2005
View
@@ -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]
@@ -130,15 +130,15 @@ module ClassMethods
# 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 @@ def prepend_before_filter(*filters, &block)
# 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.
@@ -13,15 +13,18 @@ def url_for(options = {}, *parameters_for_method_reference)
# 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
@@ -15,6 +15,24 @@ def ensure_login
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 @@ def test_running_filters_with_implicit_proc
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 @@ def test_prepending_and_appending_around_filter
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

0 comments on commit efe0348

Please sign in to comment.