Created
December 25, 2015 18:53
-
-
Save realmyst/a302fe0632d8a5a480cc to your computer and use it in GitHub Desktop.
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
class StateEventInput < SimpleForm::Inputs::CollectionSelectInput | |
def collection | |
object.send(transitions) | |
end | |
def input(wrapper_options) | |
label_method = :human_event | |
value_method = :event | |
current_state = template.content_tag(:div, template.content_tag(:span, "Current state: #{object.send(human_name)}", :class => "label label-info") ) | |
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) | |
out = @builder.collection_select( | |
attribute_name, collection, value_method, label_method, | |
input_options, merged_input_options | |
) | |
(out << current_state).html_safe | |
end | |
private | |
def machine_name | |
attribute_name.to_s.gsub "_event", "" | |
end | |
def transitions | |
"#{machine_name}_transitions" | |
end | |
def human_name | |
"human_#{machine_name}_name" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment