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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:33:17+00:00 2026-05-24T01:33:17+00:00

<%= image_tag message.photo.url(:small) %> I have paperclip installed and the above code displays an

  • 0
<%= image_tag message.photo.url(:small) %>

I have paperclip installed and the above code displays an image that the user uploads which has been resized to :small (in this case 40x40px. How can I get my page to display this image only if it exists? Currently if the message includes a photo that photo is displayed but all other messages show broken image links. Thanks

  • 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-24T01:33:18+00:00Added an answer on May 24, 2026 at 1:33 am

    Paperclip adds the name of the attachment suffixed with a “?” to the attached model as a helper method to allow you to see whether or not there is an attachment. In your case, the helper method would be photo? on the message class. You could use it with the tertiary operator in this manner:

    <%= message.photo? ? image_tag message.photo.url(:small) : "" %>
    

    Or, if you’d like to show a default no-image image when there is no image…

    <%= image_tag message.photo? ? message.photo.url(:small) : url_to_no-image_image %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the code: <%= image_tag site.photo.url(:small) if site.photo.file? %> to tell my
I have a standard devise edit user form: <%= form_for(resource, :as => resource_name, :url
I am getting an error message that says my image cannot be displayed because
Situation: I have a simple XML document that contains image information. I need to
<%- if @last_msg.photo? -%> <%= image_tag @last_msg.photo.url(:listsize) %> <%- else -%> <%= image_tag(default.jpg) %>
I'm following the railscast for PaperClip and have ImageMagick installed. I followed his video
I have a program that takes an image and writes that out to a
Working on iPhone app that takes a photo and then uploads it to a
I have an image tag enclosed in an anchor element like this: <a href='$image'><img
I am trying to access an asp Image tag in my code behind so

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.