19 May '13, 4pm
Neat! Decent Exposure makes it easier to write concise controllers:
In this episode we’re going to look at a gem called decent_exposure . This is a simple gem with a nice concept. We can use it to create an interface of methods in the controller that the view can access instead of using instance variables. The gem uses a method called expose to define this interface. Before we look at decent_exposure we’ll try applying this concept manually. The application we’ll be working with is a simple blogging application with many Articles , each of which can have many Comments . The ArticlesController contains pretty standard controller code. For example in the index action it creates an instance variable called @articles . /app/controllers/articles_controller.rb class ArticlesController < ApplicationController def index @articles = Article.order(:name) end #Other actions omitted. end In the index view code we then use @articles to loop through eac...