Instantly share code, notes, and snippets.

Embed
What would you like to do?
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