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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:01:15+00:00 2026-06-05T13:01:15+00:00

I am new to coding – and have not enough reputation to comment this

  • 0

I am new to coding – and have not enough reputation to comment this answer:
Rails 3: Uniqueness validation for nested fields_for

So I am creating this question as "Part 2" 🙂

I am a web designer but curious to learn coding, held with this from my days.

# app/validators/nested_attributes_uniqueness_validator.rb   
class NestedAttributesUniquenessValidator < ActiveModel::EachValidator
        record.errors[attribute] << "Products names must be unique" unless value.map(&:name).uniq.size == value.size
      end
end

above code with "ActiveModel::EachValidator" throw this error:

"undefined method `map’ for "Area 1":String"


# app/validators/nested_attributes_uniqueness_validator.rb   
class NestedAttributesUniquenessValidator < ActiveModel::Validator
    record.errors[attribute] << "Products names must be unique" unless value.map(&:name).uniq.size == value.size
  end
end

above code with "ActiveModel::Validator" throw this error:

"Subclasses must implement a validate(record) method. "


this is model file:

class Area < ActiveRecord::Base


  validates :name,
            :presence => true,
            :uniqueness => {:scope => :city_id},
            :nested_attributes_uniqueness => {:field => :name}

  belongs_to :city

end

You can find complete code over here:
https://github.com/syed-haroon/rose

  • 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-05T13:01:17+00:00Added an answer on June 5, 2026 at 1:01 pm

    I found the answer over here :

    https://rails.lighthouseapp.com/projects/8994/tickets/2160-nested_attributes-validates_uniqueness_of-fails

    &

    validates_uniqueness_of in destroyed nested model rails

    This is for rails 2, one line need to me modified over here:
    add_to_base has been deprecated and is unavailable in 3.1. Use self.errors.add(:base, message)

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

Sidebar

Related Questions

Im very new to all coding including jquery. I though this would have been
ok i am new to coding and cocos2d i have this shooting code that
We implemented new coding standards, which call for our private members to have a
I am new to coding python. I am hoping to modify this code to
Im new on Google Chrome Extensions coding, and i have some basic questions. I
New to iOS coding, so this is probably more of a syntax question than
I'm new to computer coding and have just finished coding an app and tested
I am new to coding (never taken a CS class and have a very
I'm pretty new to coding with streams but now I have to do it
I have implemented a quadtree in Mathematica. I am new to coding in a

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.