Created
November 15, 2011 03:42
-
-
Save jlberglund/1366063 to your computer and use it in GitHub Desktop.
SimpleForm Custom Input for jQuery Tokeninput
This file contains 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
# SimpleForm (https://github.com/plataformatec/simple_form) | |
# jQuery Tokenninput (http://loopj.com/jquery-tokeninput/) | |
class TokenInput < SimpleForm::Inputs::Base | |
def input | |
input_html_options[:"data-url"] = "/#{reflection.klass.name.tableize}.json" | |
if @builder.object.send(reflection.name).nil? | |
if input_html_options[:value] | |
object = reflection.klass.find(input_html_options[:value]) | |
end | |
else | |
object = @builder.object.send(reflection.name) | |
end | |
input_html_options[:"data-pre"] = "[#{object.to_json(:only => [:id, :name])}]" if object | |
"#{@builder.text_field(attribute_name, input_html_options)}".html_safe | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment