Posts
link_to_remote_if / link_to_remote_unless with block
25 Mar 2010
Tags:
link_to_remote_unless, link_to_remote_if, helpers
I needed to pass an html block, much like the functionality we have with link_to, but for the link_to_remote helpers. So I've looked for implementations and I can't find anything that suits my taste. So I created my own helpers.
Here you go.
ruby
def link_to_remote_if(condition, name, options = {}, html_options = nil, &block) if condition concat link_to_function(capture(&block), remote_function(options), html_options || options.delete(:html)) else if block_given? block.arity <= 1 ? yield(name) : yield(name, options, html_options) else name end end end def link_to_remote_unless(condition, name, options = {}, html_options = nil, &block) link_to_remote_if !condition, name, options, html_options, &block end