Created
February 22, 2018 06:11
-
-
Save Mk-Etlinger/9a17dea7005f695df6493f37823d305c to your computer and use it in GitHub Desktop.
Metaprogram setting your resource as an instance variable
This file contains hidden or 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 ApplicationController < ActionController::API | |
before_action :authenticate_user | |
def sorcery | |
controller_name = params['controller'] | |
controller_name.chop! | |
model_name = controller_name.capitalize | |
instance_variable_set('@' + controller_name, Object.const_get( model_name ).find_by(id: params[:id])) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment