module ActionView::Helpers::UrlHelper
def link_to_unless(condition, name, options = {}, html_options = {}, &block)
# If not...
# => Reply
# If the user is logged in...
%>
end
link_to(name, { :controller => "accounts", :action => "signup" })
link_to_unless(@current_user.nil?, "Reply", { :action => "reply" }) do |name|
<%=
# => Reply
# If the user is logged in...
<%= link_to_unless(@current_user.nil?, "Reply", { :action => "reply" }) %>
==== Examples
accepts the name or the full argument list for +link_to_unless+.
than just the plaintext link text), you can pass a block that
returned. To specialize the default behavior (i.e., show a login link rather
+options+ unless +condition+ is true, in which case only the name is
Creates a link tag of the given +name+ using a URL created by the set of
def link_to_unless(condition, name, options = {}, html_options = {}, &block) if condition if block_given? block.arity <= 1 ? capture(name, &block) : capture(name, options, html_options, &block) else name end else link_to(name, options, html_options) end end