Last active
August 29, 2015 14:26
-
-
Save Crisfole/dc5f558b21b71ed36d10 to your computer and use it in GitHub Desktop.
For Jeremy
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
# In Application Controller: | |
# Rename your current version of 'current_user' like so: | |
def _current_user | |
# Current User Code | |
end | |
# Change _current_user to something like this: | |
def current_user | |
model = self.class.class_variable_get :@@model rescue nil | |
param = self.class.class_variable_get :@@param rescue nil | |
if model | |
model.find(params[param]).customer | |
else | |
_current_user | |
end | |
end | |
# In all subclasses of ApplicationController that require the user to be logged in: | |
class VideoController < ApplicationController | |
@@model = Video | |
@@param = :video_id | |
# Rest of your code here | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment