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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:34:37+00:00 2026-06-17T22:34:37+00:00

I have a model Camping which has_many Images . At least one image is

  • 0

I have a model Camping which has_many Images. At least one image is required on Camping:

class Camping < ActiveRecord::Base
  attr_accessible :images_attributes
  has_many :images
  validates_presence_of :images, :message => "At least one image is required"
  accepts_nested_attributes_for :images, :allow_destroy => true
 end

Then, in active_admin, which uses formtastic, I render the error message At least one image is required, with f.semantic_errors:

ActiveAdmin.register Camping do
  form :html => { :multipart => true } do |f|
     f.semantic_errors :images
     #....
     f.inputs "Images" do
      f.has_many :images do |img|
        #....
      end
    end
    #....
  end
end

This renders as:

Example output of error

Images At least one image is required.

How can I make it render: At least one image is required?

changing the f.semantic_errors :images into ‘f.semantic_errors (removing :images) makes it render nothing; no error at all.

Note: The API documentation seems to imply that Formtastic always adds the :attribute name to the error; but I am not entirely sure how this code works.

  • 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-06-17T22:34:38+00:00Added an answer on June 17, 2026 at 10:34 pm

    If you want to use such custom messages you can add error messages that are related to the object’s state as a whole, instead of being related to a specific attribute

    Change this

    validates_presence_of :images, :message => "At least one image is required"
    

    to something like

       validate :should_have_images
       def should_have_images
           errors.add(:base, "At least one image is required") if images.blank?
       end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have model: class Topic < ActiveRecord::Base attr_accessible :title, :description has_many :comments, :dependent =>
I have model: class RealtyPhoto < ActiveRecord::Base attr_accessible :name, :photo mount_uploader :photo, RealtyPhotoUploader belongs_to
I have model User class User < ActiveRecord::Base has_and_belongs_to_many :roles attr_accessible :login, :email, :password,
im have model Category. class Category < ActiveRecord::Base has_ancestry :cache_depth => true, :depth_cache_column =>
I have model with default_scope: class Campaign < ActiveRecord::Base default_scope where(campaigns.status != ?, archive)
So, i have model User class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable,
I have model with tag context: class Product < ActiveRecord::Base acts_as_taggable_on :categories end I'm
I have model with custom primary key: document.rb class Document < ActiveRecord::Base set_primary_key token
I have a Camping which has one Author . An Author has many Campings
I have Model class which extends Mage_Core_Model_Abstract . I have a resource which extends

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.