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

  • Home
  • SEARCH
  • 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 7632859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:43:58+00:00 2026-05-31T06:43:58+00:00

Currently in my application I have two possible textboxes. One for a local image

  • 0

Currently in my application I have two possible textboxes. One for a local image upload, and another for a remote image URL. I am making sure that if the user selects a local image file then the “Remote Image URL” gets cleared, and vice versa, so only one box is filled.

I’m trying to do some validation on them using :validate_image_fields. How do I determine which box is filled out in that validation method?

new.html.erb

<%= form_for @painting, :html => {:multipart => true} do |f| %>
    <p>
      <%= f.file_field :image %>
    </p>
    <p>
      <%= f.label :remote_image_url, "or image URL" %><br />
      <%= f.text_field :remote_image_url %>
    </p>
  <p><%= f.submit %></p>
<% end %>

gallery.rb

class List < ActiveRecord::Base
  attr_accessible :description, :image, :remote_image_url

  validate :validate_image_fields

  def validate_minimum_image_size
    # how do i determine if it is a remote image or local image?
  end

Thank you!

  • 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-31T06:43:59+00:00Added an answer on May 31, 2026 at 6:43 am

    Since you say that ‘only one box is filled’, you could identify if a remote_url is submitted or a local file is uploaded.

    def validate_image_fields
      if remote_image_url.present?
         # condition/validations for the image url
      elsif image
         # condition/validations for uploaded image
      else
         errors.add(:base, "No image url or local image provided")
      end
    end
    

    Is this what you were looking for? I hope I got you correct.

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

Sidebar

Related Questions

I have an application in which I'm currently using a two column table in
I'm developing an application which currently have hundreds of objects created. Is it possible
I'm currently writing a web application that have about 6-12 pages. On each one
Currently I have one monitor application in production. The job of this monitor is
I have this two routes currently in my application after decommenting out many other
The database I am working with currently does have two tables, one holding the
I currently have a single solution that contains both the one application developed so
Currently on my application I have a form where I ask the user to
I have an application (currently written in Python as we iron out the specifics
I currently have an application which needs to have an awareness of which monitor

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.