class ChaptersController < ApplicationController
  before_filter :find_book
  
  caches_action :show
  
  def show
    @chapter = @book.chapters.detect { |chapter| chapter.position == params[:id].to_i }
  end
  
  private
  
  def find_book
    @book = Book.find(params[:book_id])
  end
end
class ChaptersController < ApplicationController
  before_filter :find_book
  
  caches_action :show
  
  def show
    @chapter = @book.chapters.first(conditions: { position: params[:id] })
  end
  
  private
  
  def find_book
    @book = Book.find(params[:book_id])
  end
end
Use for finding a chapter for a given position rather than the array version
Use  for finding a chapter for a given position rather than the array version
