Q:

How to display posts within specific range??  Actioncontroller Ruby on Rails

I'm trying to make Podcast pages.  On the index page, I want to display the latest podcast at the top, next three podcasts in the middle, and rest of all at the bottom of the page
For example, I have 25 episodes and want to display like below

25  at the top
22, 23, 24 in the middle
21,20,19,18 ~ 1  at the bottom

My controller
class PodcastsController < ApplicationController
  before_action :find_podcast, only: [:show, :edit, :update, :destroy]

  # GET /podcasts
  # GET /podcasts.json

  def index
    @podcasts = Podcast.order("created_at DESC").limit(1)

  end

  # GET /podcasts/1
  # GET /podcasts/1.json
  def show
    @podcasts = Podcast.all
  end

  # GET /podcasts/new
  def new
    @podcast = Podcast.new
  end

  # GET /podcasts/1/edit
  def edit
  end

  # POST /podcasts
  # POST /podcasts.json
  def create
    @podcast = Podcast.new(podcast_params)

    respond_to do |format|
      if @podcast.save
        format.html { redirect_to @podcast, notice: 'Podcast was successfully created.' } 
        format.json { render :show, status: :created, location: @podcast }
      else
        format.html { render :new }
        format.json { render json: @podcast.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /podcasts/1
  # PATCH/PUT /podcasts/1.json
  def update
    respond_to do |format|
      if @podcast.update(podcast_params)
        format.html { redirect_to @podcast, notice: 'Podcast was successfully updated.' } 
        format.json { render :show, status: :ok, location: @podcast }
      else
        format.html { render :edit }
        format.json { render json: @podcast.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /podcasts/1
  # DELETE /podcasts/1.json
  def destroy
    @podcast.destroy
    respond_to do |format|
      format.html { redirect_to podcasts_url, notice: "#{@pocast.title} was successfully destroyed." } 
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions. 
    def find_podcast
      @podcast = Podcast.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through. 
    def podcast_params
      params.require(:podcast).permit(:episode_url, :episode_title, :episode_description, :episode_audio_url, :episode_number)
    end
end

index.html.haml
%section.no-spacing
  .row   
    .columns.large-12
      %h1
        %b
          Career Daily
        %p
          Need latest news on your career?  Looking for advices?  You found us!  Andy Moore, the host of Career Dailey, delivers you the most...

    .columns.large-12
      - @podcasts.each do |podcast|
         %h3
           = podcast.episode_number
           = podcast.episode_audio_url
           = podcast.episode_description

I could display the latest one, but stuck at showing three(2nd, 3rd, 4th) and rest of the pages (5th ~ all)
Appreciates your help in advance. 

A:

Your @podcasts object contains each podcast you need to render. 
In your view, - @podcasts.each do |podcast| is looping through all of the podcasts.  Don’t loop through them all, the below will create loops for 2/3/4 and a separate one for the rest. 
Use @podcasts[1..3].each do |podcast| to loop through the 2nd, 3rd & 4th.  Then @podcasts[4..-1].each do |podcast| to loop through the remainder. 
The above uses ruby’s array index method; to get only part of the array (all your podcasts).  Have a look at https://ruby-doc.org/core-2.7.1/Array.html#class-Array-label-Accessing+Elements for more on this. 
For the top podcast, you don’t need a loop, just render out @podcasts.first.episode_description And the other attributes you want to render.  Rails (maybe active record specifically) just allows .first as a convenient syntax for array index [0]
You asked earlier about 3 separate variables in your controller as an approach; you don’t want that - there is a real danger you’ll end up making 3 DB queries instead of just the one - much much slower. 