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 6949147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:54:59+00:00 2026-05-27T13:54:59+00:00

Im working on a rails app where a user has the ability to upload

  • 0

Im working on a rails app where a user has the ability to upload photos. When a user uploads their photos it will appear on their profile. Everything works great besides when there is no photos created then I am unable to view the user profile page because of the photo being nil.

here is my show method in the users_controller.rb

def show 
@user = User.find_by_id(:id)
@photo = @user.photos.find(params[:id])
end

Here is my show.html.erb

 <% for photo in @user.photos %>
  <%= photo.title %>
  <%= photo.description %>
  <%= image_tag photo.image_url(:thumbnail) %>
  <%= link_to "Show", photo %>
 <br>
 <% end %>

How can I bypass this error?

  • 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-27T13:54:59+00:00Added an answer on May 27, 2026 at 1:54 pm

    The code for your action seems wrong…

    It should be this:

    def show 
      @user = User.find(params[:id])
      #@photo = @user.photos.find(params[:id])
    end
    

    I commented out the third line on purpose, because I’m not sure what it is you want to do there, yet.

    The @user variable needs to be defined using params[:id], given that this is the show action for the UsersController, so the id for the user will be passed through as params[:id].

    But then you go and use this to find the photo for the user, which is what confuses me… the Photo record’s id attribute is probably not going to be the same as the User record’s id attribute.

    So what is it?

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

Sidebar

Related Questions

I'm working on a Rails 3.1 app that has the following models: User: class
I'm working on a Rails 3 app where a user's profile has_many :todos .
I'm working on a rails app that has a whole bunch of before filters
I'm working on a Rails app that will contain information on a bunch of
So everything works. But if a user has firebug's console open, they'll see a
I am working on a rails 3 app which has different languages in my
So Im working on a rails app where users can comment on photos or
I working on an app with user authorization. It has a List and User
My Rails 3.1 app has two user models: User and Admin. I'm using Devise.
I am working on a Ruby on Rails app which which has the following

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.