a fast way would be to use :pluck, if you are just returning an array of titles (I am guessing no :id) , then this would be very fast
def index
@titles = Video.pluck(:title)
respond_to do |format|
format.xml { render :xml => @titles }
format.json { render :json => @titles }
end
end
:pluck will be way faster than any of the other options because it returns an array with just the data requested. It doesn't instantiate an entire ActiveRecord Object for each database row. Because its ruby, those instantiations are what take most of the time. You can also do :
@videos_ary = Video.pluck(:id, :title)
response = @videos_ary.map {|va| { id: va[0], title: va[1] }}
if you dont want to get your SQL pencil out, this is pretty good