Last active
December 29, 2015 11:09
-
-
Save laspluviosillas/7661884 to your computer and use it in GitHub Desktop.
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
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 |
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
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