DRY Controllers in Rails 3.2

前端 未结 3 2242
有刺的猬
有刺的猬 2021-02-15 15:00

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         


        
3条回答
  •  甜味超标
    2021-02-15 15:08

    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
    

提交回复
热议问题