DRY Controllers in Rails 3.2

dry, ruby, ruby-on-rails-3

Solution

You could use respond_with for these actions.

class AnimalController < ApplicationController
  respond_to :html, :json

  def index
    @animals = current_user.animals.valid_animals.search(params[:search], params[:page])
    respond_with @animals
  end   
end

Problem

Following code climate analysis, I found that my controllers are not DRY as it could be. The methods like: ``` def index @animals = current_user.animals.valid_animals.search(params[:search], params[:page]) respond_to do |format| format.html # index.html.erb format.json { render json: @animals } end end ``` Are basically equal in all the controllers. Basically, the scaffold rails generated code are "the same" in all controllers. How can I made it more clean and dry in a real good way? thanks in advance

Original source