-
-
Save ehrenmurdick/1927724 to your computer and use it in GitHub Desktop.
activity_sequence
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
# config/initializers/activity_order.rb | |
ACTIVITIES = [PersonalValues, PersonActions, SomeOther] | |
# config/initializer/array.rb | |
class Array | |
def relative_index(item, idx) | |
self[index(item) + idx] | |
end | |
def next(item) | |
relative_index(item, 1) | |
end | |
def prev(item) | |
relative_index(item, -1) | |
end | |
end | |
#helper file or whatever | |
def next_activity(klass) | |
get_path(ACTIVITIES.next(klass)) | |
end | |
def prev_activity(klass) | |
get_path(ACTIVITIES.prev(klass) | |
end | |
def get_path(model) | |
send(model.to_s.underscore.pluralize + "path") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment