Skip to content

Instantly share code, notes, and snippets.

@ehrenmurdick
Forked from jlsuttles/activities_helper.rb
Created February 27, 2012 22:56
Show Gist options
  • Save ehrenmurdick/1927724 to your computer and use it in GitHub Desktop.
Save ehrenmurdick/1927724 to your computer and use it in GitHub Desktop.
activity_sequence
# 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