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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:41:55+00:00 2026-05-25T00:41:55+00:00

I am using paperclip for uploading file ( video and images). Have used the

  • 0

I am using paperclip for uploading file ( video and images).
Have used the same attachment(source) for both video and images.

class Media < ActiveRecord::Base
  belongs_to :memory
  validates_attachment_presence :source
  validates_attachment_content_type :source,
    :content_type => ['video/mp4', 'image/png', 'image/jpeg', 'image/jpg', 'image/gif']
end

Now I wanted to display different error messages in different cases.

  1. When uploading file is image type but not the jpg/png/jpeg/gif.
  2. When uploaded file is video type but not the mp4

How can i achieve this ?
Any help would highly appreciated.

  • 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-25T00:41:56+00:00Added an answer on May 25, 2026 at 12:41 am

    So finally I got the solution.
    I added 2 conditional validation for the same

    class Media < ActiveRecord::Base
      belongs_to :memory
      validates_attachment_presence :source
      validates_attachment_content_type :source,
        :content_type => ['video/mp4'],
        :message => "Sorry, right now we only support MP4 video",
        :if => :is_type_of_video?
      validates_attachment_content_type :source,
         :content_type => ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'],
         :message => "Different error message",
         :if => :is_type_of_image?
      has_attached_file :source
    
      protected
      def is_type_of_video?
        source.content_type =~ %r(video)
      end
    
      def is_type_of_image?
        source.content_type =~ %r(image)
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using paperclip for uploading images in my rails application. I have 2
I am uploading multiple images (4 file fields) using paperclip, which is working fine
I am using paperclip to upload multiple images to a model, I have a
So I have a Rails 3 app using Paperclip to crop images. I have
I'm using Paperclip / S3 for file uploading. I upload text-like files (not .txt,
Using Rails 3.2. I have the following code: # photo.rb class Photo < ActiveRecord::Base
I am uploading images to S3 storage using paperclip gem. It uploads successfully. In
I'm using paperclip for uploading files, handling images is easy, but how can I
Excuse me I am using paperclip. so when i attachment a file diferent to
I'm using the following for file uploading: Rails 3.2, Paperclip (3.0.4), aws-sdk (1.5.2) &

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.