Questions tagged [validates-associated]

10 questions
18
votes
4 answers

Better validates_associated method for Rails 3?

Rails 3 includes the validates_associated which is automatically called when saving a nested model. The problem with the method is the message is terrible - "Model(s) is invalid" There have been a few posts attacking this issue for Rails…
Tony
  • 18,776
  • 31
  • 129
  • 193
12
votes
2 answers

validates_associated not checking existence of associations

Can anyone figure out what's going on here? I was able to get my code to work the way I want it to, but I can't figure out why validates_associated isn't working as I expect. Here's a snippet of my code: class Flag < ActiveRecord::Base …
Eric Hu
  • 18,048
  • 9
  • 51
  • 67
2
votes
1 answer

Using :autosave for has_one association: How to show the parent's errors when on the child's controller?

I have created a model that looks like this: class Parent < ActiveRecord::Base attr_accessible :child, :child_id has_one :child, :class_name => 'Child', :autosave => true, :inverse_of => :parent #parent's validations validates_associated…
2
votes
1 answer

Rails : Displaying associated model validations

I have got three models class RateCard < ActiveRecord::Base validate :name, :presence => true, :uniqueness => true has_many :rate_card_countries, :dependent => :destroy has_many :rate_card_details, :dependent => :destroy has_many…
Sumit Rai
  • 637
  • 1
  • 6
  • 11
1
vote
2 answers

ActiveModel: Disable failing validation when associated models fail

Does Rails3 always run validates_associated against all models by default? In a simple setup like this class Post < ActiveRecord::Base has_many :comments end class Comment < ActiveRecord::Base belongs_to :post def validate …
1
vote
1 answer

activerecord validation - validates_associated

I'm unclear on what this method actually does or when to use it. Lets say I have these models: Person < ... # id, name has_many :phone_numbers end PhoneNumber < ... # id, number belongs_to :person validates_length_of :number, :in => 9..12…
recursive_acronym
  • 2,981
  • 6
  • 40
  • 59
1
vote
1 answer

cakephp multiple select not working

I have two tables 'businesses' and business_categories and their association is like BusinessesTable.php $this->hasMany('SellerBusinessCategories', [ foreignKey => 'business_id' ]); and I have to input multiple categories to business_categories…
Anuj TBE
  • 9,198
  • 27
  • 136
  • 285
1
vote
3 answers

Rails 4 form - text field value must match a value in an associated table (autocomplete)

I have two associated models/tables app/models/city.rb has_many :businesses Fields: id, city_name, state_code app/models/business.rb belongs_to :city Fields: id, biz_name, address, city_name, state_code, zip In the new business form where you…
0
votes
1 answer

Validates_overlap custom message?

i try the gem validates_operator. I need to custom my message for this validation: validates :arrival_date, :departure_date, overlap: { scope:"place_id", message_title: "Error", message_content:"Impossible to booking this place for this…
0
votes
1 answer

has_one validates_associated firing inconsistently despite 'on: :create'

I'm seeing really weird behaviour when checking valid? on a model that has a validates_associated :contact, on: :create. If I make two calls to valid? the first is true and the second is false. This is a minimal version of the models, hopefully it's…
jim
  • 1,025
  • 12
  • 17