Skip to content

Instantly share code, notes, and snippets.

@ayumi
Created November 28, 2012 23:45
Show Gist options
  • Save ayumi/4165614 to your computer and use it in GitHub Desktop.
Save ayumi/4165614 to your computer and use it in GitHub Desktop.
conditionally uneditable form tag, extends Rails form helper
module ActionView
module Helpers
module FormTagHelper
def uneditable_tag(method, name, opts={})
if yield
send method, name, opts
else
value = defined?(object) ? object.send(name) : opts[:value]
content_tag :span, value, opts.merge({ :class => "uneditable-input #{opts.delete(:class)}" })
end
end
end
class FormBuilder
include TagHelper
include FormTagHelper
def uneditable(*args, &blk)
uneditable_tag *args, &blk
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment