Created
November 28, 2012 23:45
-
-
Save ayumi/4165614 to your computer and use it in GitHub Desktop.
conditionally uneditable form tag, extends Rails form helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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