title: display images in rails
body: <p>I am trying to display the the first image from the albums table that belongs to the a post </p>
  
  <pre><code>class Post &lt; ActiveRecord::Base
    has_many :albums, dependent: :destroy
  end
  
  class Album &lt; ActiveRecord::Base
    belongs_to :post
  end
  </code></pre>
  
  <p>and in the post index I wanted to display the one of the images that belongs to a post in the post/index page</p>
  
  <pre><code>class PostsController &lt; ApplicationController
    before_action :signed_in_user, only: [ :new, :create, :edit, :update, :destroy]
    before_action :set_post, only: [:edit, :update, :destroy] #:show,
  
  
    def index
       @albums = Album.all
      @posts = Post.all
    end
  
    def show
      @post = Post.find(params[:id])
      @user = @post.user(params[:id])
      @album = Album.new
      @album.post_id = @post.id
    end
  
    def new
      @post = Post.new
    end
  
    def create
      if current_user
      @post = current_user.posts.build(post_params)
  
        if @post.save
           redirect_to @post, notice: 'Post was successfully created.' 
        else
           render action: 'new'
         end
        end
      end
  end
  </code></pre>
  
  <p>this is the albums controller</p>
  
  <pre><code>class AlbumsController &lt; ApplicationController
    def create
      @album = Album.new(album_params)
      @album.post_id = params[:post_id]
  
      @album.save
      redirect_to post_path(@album.post), notice: 'photo added successfully'
    end
  
  end
  </code></pre>
  
  <p>below is the views/posts/index.html.erb page</p>
  
  <pre><code>  &lt;% @posts.each do |post| %&gt;
      &lt;%= post.title %&gt;
       &lt;% post.albums.each do |album| %&gt;
         &lt;%= image_tag album.image.url(:thumb) %&gt;
       &lt;% end %&gt;
    &lt;% end %&gt;
  </code></pre>
  
  <p>what do I need to do so that I can display the first image in a post?</p>