Skip to content

Instantly share code, notes, and snippets.

@dkumar431
Created March 27, 2018 03:34
Show Gist options
  • Save dkumar431/cbdef494bc89f12d4485a6887671470f to your computer and use it in GitHub Desktop.
Save dkumar431/cbdef494bc89f12d4485a6887671470f to your computer and use it in GitHub Desktop.
def get_user_progress
if @course.present? && @resource.present?
course_tracking = Tracking.where(user_id: current_user.id, key: @course.key).first
return if course_tracking.nil?
if course_tracking.is_completed
@progress = 100
@quizFinished = true
else
@progress = course_tracking.get_course_progress(@course)
@quizFinished = course_tracking.quizzies_completed?(@course)
end
end
end
@asahu12
Copy link

asahu12 commented Mar 27, 2018

def get_user_progress
  if course_and_resource_present?
    course_tracking = Tracking.where(user_id: current_user.id, key: @course.key).first
    return if course_tracking.nil?
    @progress, @quizFinished = fetch_course_progress(course_tracking)
  end
end
private 
def fetch_course_progress(course_tracking)
  return [100, true] if course_tracking.is_completed
  [course_tracking.get_course_progress(@course),course_tracking.quizzies_completed?(@course)]
end

def course_and_resource_present?
  @course.present? && @resource.present?
end

@dkumar431
Copy link
Author

dkumar431 commented Mar 27, 2018

  1. I have a pages_controller.rb containing show method which will render the whole page.


  2. I have a before_action filter to track the page view.


  3. If in my application you are logged in as manager, you will have access to 2 variables current_user and current_manager. To login as a manager you have to first login as doctor(current_user) and then manager(current_manager).


  4. **If you are logged in manager , i do not want pages to be tracked.**


  5. I can do
    before_action :save_user_progress, only: [:show], if: ->{ current_manager.nil? }
    
 save_user_progress method contains something similar to Tracking.create (…….)


  6. There are some other places also where Tracking.create can be called in future.


  7. So my question which is the right place for this checking 
controller or model?


  8. If model, i do not have access to current_manager from model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment