How to use descent exposure in Ruby on Rails | Inkoop Blog

How to use descent exposure in Ruby on Rails. We talk about its features, benefits and when and how to use the gem.

Posted by Ameena on 22 Apr 2018

Although Decent exposure is a simple gem, it has different concept.

When you do not want to use instance variables across controller and view. You can definitely look into this gem.

In its term, it is used to expose a model in the controller.

class ProductsController < ApplicationController
  expose :product

The gem provides a method called expose, which will either find the object with the help of params. If not present it builds the object. It performs either of the below query

Product.find(params[:product_id] || params[:id])


Now, you can use product instead of instance variable across the products controller and view.

It also handles custom behaviour if you pass in blocks,

class ProductsController < ApplicationController
  expose(:products) { Product.all }

Likewise, you can work with associations

class ReviewsController < ApplicationController
  expose(:reviews) { }

Keep Coding !!!


Have a Project in mind?