Skip to content

Instantly share code, notes, and snippets.

@laspluviosillas
Last active December 29, 2015 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laspluviosillas/7661884 to your computer and use it in GitHub Desktop.
Save laspluviosillas/7661884 to your computer and use it in GitHub Desktop.
class ResultSetsController < ApplicationController
def index
@survey = Survey.find(params[:id]) # should be :survey_id if you want to conform to rails standard.
@quiz = @survey.quiz # try to retrieve quiz from survey, you should not have to load all the result sets to find the right quiz id.
@result_sets = Survey.result_sets.owned_by(result_set_owner)
# Rest of code follows below but requires major refactoring.
end
private
def result_set_owner
if current.loginable_type == 'Student'
params[:user_id] || current_user.id
else
params[:user_id]
end
end
end
class ResultSet < ActiveRecord::Base
def self.owned_by(owner_id)
return self if owner_id.nil?
where(user_id: owner_id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment