app/helpers/activity_helper.rb
def previous_next_activity_path(series, activity)
    return [nil, nil] if series.blank?

    previous_ex = nil
    next_ex = nil

    # Function that gets the path to the activity.
    get_ex_path = ->(ex) { course_series_activity_path(I18n.locale, series.course, series.id, ex) }

    series.activity_ids.each_with_index do |series_activity_id, idx|
      next unless series_activity_id == activity.id

      previous_ex = get_ex_path.call(series.activity_ids[idx - 1]) if idx > 0
      next_ex = get_ex_path.call(series.activity_ids[idx + 1]) if idx + 1 < series.activities.length
      break
    end

    [previous_ex, next_ex]
  end
# Finds the paths to the previous and next activity in a series, given the
# current activity.
Finds the paths to the previous and next activity in a series, given the
current activity.
Finds the paths to the previous and next activity in a series given the current activity .
def previous_next_activity_path(series, activity)
    return [nil, nil] if series.blank?
    previous_ex = nil
    next_ex = nil
    get_ex_path = ->(ex) { course_series_activity_path(I18n.locale, series.course, series.id, ex) }
    series.activity_ids.each_with_index do |series_activity_id, idx|
      next unless series_activity_id == activity.id
      previous_ex = get_ex_path.call(series.activity_ids[idx - 1]) if idx > 0
      next_ex = get_ex_path.call(series.activity_ids[idx + 1]) if idx + 1 < series.activities.length
      break
    end
    [previous_ex, next_ex]
  end
def previous_next_activity_path ( series , activity ) return [ nil , nil ] if series . blank? previous_ex = nil next_ex = nil get_ex_path = -> ( ex ) { course_series_activity_path ( I18n . locale , series . course , series . id , ex ) } series . activity_ids . each_with_index do | series_activity_id , idx | next unless series_activity_id == activity . id previous_ex = get_ex_path . call ( series . activity_ids [ idx - 1 ] ) if idx > 0 next_ex = get_ex_path . call ( series . activity_ids [ idx + 1 ] ) if idx + 1 < series . activities . length break end [ previous_ex , next_ex ] end
Finds the paths to the previous and next activity in a series, given the
current activity.
Finds the paths to the previous and next activity in a series given the current activity .
# Function that gets the path to the activity.
series
activity