Skip to content

Instantly share code, notes, and snippets.

@Bonias
Last active May 24, 2017 10:46
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 Bonias/4ce18e30881480f42a9d to your computer and use it in GitHub Desktop.
Save Bonias/4ce18e30881480f42a9d to your computer and use it in GitHub Desktop.
decent_exposure with responders integration
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
self.responder = ApplicationResponder
respond_to :html
decent_configuration do
strategy DecentExposure::StrongParametersStrategy
end
end
# app/responders/application_responder.rb
class ApplicationResponder < ActionController::Responder
include Responders::FlashResponder
include Responders::HttpCacheResponder
end
# app/controllers/admin/banners_controller.rb
class Admin::BannersController < Admin::BaseController
expose(:resource, model: :banner, attributes: :resource_params)
expose(:resources, model: :banner)
def index
self.resources = begin
@q = resources.search(params[:q])
@q.sorts = 'created_at DESC' if @q.sorts.blank?
@q.result.page(params[:page]).per(params[:per_page])
end
respond_with :admin, resources
end
def show
respond_with :admin, resource
end
def new
respond_with :admin, resource
end
def create
resource.save
respond_with :admin, resource
end
def edit
respond_with :admin, resource
end
def update
resource.save
respond_with :admin, resource
end
def destroy
resource.destroy
respond_with :admin, resource
end
private
def resource_params
params.require(:banner).permit(:title, :color, :icon, :url)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment