Skip to content

Instantly share code, notes, and snippets.

@thedelchop
Last active January 15, 2016 16:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thedelchop/29468177845e21060736 to your computer and use it in GitHub Desktop.
Save thedelchop/29468177845e21060736 to your computer and use it in GitHub Desktop.
A controller that can not be extended without being modified
class ApplicationController < ActionController::Base
before_filter :load_user
def load_user
@user ||= User.find(params[:user_id])
end
end
class EventsController < ApplicationController
def index
render json: @user.events, each_serializer: EventsSerializer
end
end
class RegistrationsController < ApplicationController
def create
# Some logic to sign up
render json: @user, each_serializer: UserSerializer
end
end
class TasksController < ApplicationController
def index
render json: @user.tasks, each_serializer: TasksSerializer
end
end
class UsersController < ApplicationController
def show
render json: @user, serializer: UserSerializer
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment