Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7094067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:31:03+00:00 2026-05-28T08:31:03+00:00

So I was implementing a feature that allows users to set default profile photos

  • 0

So I was implementing a feature that allows users to set default profile photos and default photo album cover photos.

Completed these features now:

I have the following tables in my database:
User(s) (has one profile, has many PhotoAlbums)
Profile(s) (belongs to user) contains photo_id
PhotoAlbum(s) (belongs to user, has many photos) contains photo_id
Photo(s) (belongs to PhotoAlbum)

Displaying the users default photo is straight forward.
I’m having trouble displaying the users default album photo now.

This is how I display users default profile photo:

UsersController:

default_profile_photo_id = current_user.profile.photo_id
 @default_photo = Photo.find(default_profile_photo_id) 

Users view show template:

<%= link_to image_tag(@default_photo.image, :width =>"200"), @user.username %> 

Currently for photoalbums default photos I show the first photo inside that photo album:

   <% for photo_album in @photoalbums %>
   <%= link_to photo_album.album_title, photo_album %>    
   <%= link_to image_tag(photo_album.photos.first.image, :width =>"100"), photo_album %>
   <%= link_to "Edit Album", edit_photo_album_path(photo_album) %> 
   <%= photo_album.photos.size %>
   <% end %>

Associated controller action:

  def index
    @photoalbums = PhotoAlbum.find_all_by_user_id(current_user.id)
  end

What I need to do is during the for loop, pull the row from the photos table that has an id that matches the photo_id of the photoalbum that the loop is currently looping so that on my index template I can pull the image from the matching photo row and display it.

I’ve tried endless solutions but none work..

I feel I need a helping hand from an experienced programmer.

Kind regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:31:04+00:00Added an answer on May 28, 2026 at 8:31 am

    PhotoAlbum model:

    belongs_to :photo
    

    view:

    image_tag(photo_album.photo(photo_album.photo_id).image
    

    Very, very simple fix inspired by Frederick Cheungs comment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm implementing an Auto-Twitter feature into my website that allows users to Auto-Post content
When implementing an interface in eclipse, it has a really nice feature that lets
I'm currently implementing a HTML canvas based webapp that features panning. Is there a
is that possible to hide specific nodes in VirtualStringTree? I'm implementing filtering feature (the
I'm implementing a feature that when the user press on any point in the
I need help implementing a new feature in an existing product that's implemented using
I need to add functionality to my WPF application (in C#) that allows users
I've just started using Git and find that whilst I am implementing a feature
In some editors there exist plugins implementing a feature called hungry backspace or hungry
Any re-sources or best-practices for implementing dynamic class re-loading feature into a J2EE WebApp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.