How to use descent exposure in Ruby on Rails

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 !!!


What do we do?

We work on website development using Ruby on Rails, NodeJS, ReactJS, AngularJS. View all the services we provide here.

Contact us See our work