similar to: validation error reporting on child object

Displaying 20 results from an estimated 20000 matches similar to: "validation error reporting on child object"

2006 Mar 11
2
How do you display validation errors when validating child models?
I can''t seem to figure out how to get child validation error messages to display. I''m going through the simple blog example DHH uses in his video. In the example, a comment belongs_to a post. Validating posts works fine and the errors are displayed as they should be. When I try to validate a comment using: validates_presence_of :summary It does the proper validation by not
2006 Sep 07
6
form_for - Child object - how to set parent id
Hi All, I am just trying to learn ruby/rails so please don''t flame me if this is a stupid question. As a learning project I decided to create my own blog using ROR. I have created a controller that shows paged blog entries, and below each blog is a list of comments along with a form alowing the user to add a new comment. To create the form for the comment entry I used form_for
2006 Apr 05
2
How to add add child items to parent via parent show view?
I want to know the standard/easiest way to add items to a parent? Example: comment added to post I would like this to happen in the ?show? view of post using a form that is shown when the user clicks the ?add new? button/link. I would also like validation on the child form with the validation errors appearing in the post show? view. Two problems are presented: 1) When the user clicks the
2008 Oct 09
2
has_many validation the Rails way
Okay, this is something I run into a lot and don''t really have a great solution. Here is a simple example: class Blog < ActiveRecord::Base has_many :posts validates_presence_of :name end class Post < ActiveRecord::Base belongs_to :blog validates_presence_of :name validates_presence_of :blog_id end Now, if I want to create a blog and post at the same time I
2006 Jun 28
3
couple newbie questions
Hello Folks, I am starting out with RoR and just browsed through Dave''s book ? couldn''t stop reading. I started building a prototype to get better hands on experience and I have run into two simple issues that I am hoping will be a quick answer for some of you experts out there. *Issue 1:* >From within a "companies" controller and list_companies.rhtml view
2006 Mar 25
3
validates_presence_of validation order?
I have a form with 3 fields: user_id, email and password. All 3 fields are required, so I have a "validates_presence_of :user_id, :email, :password" in my model. Works, but the validation errors show up in a different order than I specificed in the validates_presence_of statement. Is there a way to specify the order in which the validations (and corresponding error messages) should
2009 Feb 19
3
Associated child records not created on creation of a parent.
I am trying to create a record with association. Within the create method, I would also like to pre-populate dependent (has_many) records from a template in the database. The child records are <u>mysteriously rolled back </u> if I insert them in a loop. If I try to insert a single child record, it works.I have read the books and tried to google my way out of this but am at a dead
2007 Dec 22
3
collection_select validation problem
I''m trying to assign a parent foreign key value using collection_select from my child "new" form. The problem I''m having is if I do not make a selection, I get the following error instead of the Rails validates_presence_of error: You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating
2007 Jun 21
1
Validation Through Multiple Models from one Form
Hey All, I have a form that submits data to multiple models. I have class Man < ActiveRecord::Base has_many :notes has_many :contacts validates_associated :contacts, :notes validates_presence_of :first_name validates_presence_of :last_name class Contact < ActiveRecord::Base belongs_to :man validates_presence_of :contact_info class Note < ActiveRecord::Base
2006 Dec 16
2
Validate some fields only on object creation, not update
I''m having a problem with my User model. Originally I had alot of validation, including this: validates_presence_of :password_confirmation, :password validates_length_of :password, :within => 4..50 validates_confirmation_of :password However, this made it impossible to edit a user without setting his password, which I don''t want. So I tried to isolate the above validations
2006 Apr 07
6
validation nightmare
Please help, I am really at a loss at how validation is supposed to work in rails. Model contains acts_as_tree I want to force my NEW objects to have a parent I do NOT want existing object to have a parent so I only want to have parent_id on create, NOT on update. I am trying this: def validate_on_create validates_presence_of :parent_id, :message => "You must specify a
2006 Jul 14
2
Validation not executing on save - need help debugging
All, The validation on my object is not being triggered any more on the save action. I''m trying to debug it. In attempting to debug it, I''m trying to understand exactly what validates_presence_of does. Basically, I''m trying to see if for some reason, validates_presence_of doesn''t think my fields are blank now. I see from the API docs. that
2012 Nov 17
2
Help needed for error in foreign key validation
I have two models bank and country. User should only associate a Bank with a country id present in the country table and I put validates presence of country to enforce it but i get error mysql2::Error: Unknown column ''countries.bank_id'' in ''where clause'': SELECT `countries`.* FROM `countries` WHERE `countries`.`bank_id` = 17 LIMIT 1 when updating the bank
2006 Feb 08
1
Weird validation issue
Hi, I''m having a weird validation issue. Validation isn''t working for certain attributes and, for some reason, it''s also affecting things outside of validation. For campers on certain camp types, we require some information about their school. I tried to validate the information this way: validates_presence_of :school_type, :if => Proc.new { |c| !c.booking.nil?
2008 Feb 27
8
ActiveRecord validation messages not I18N-friendly and enforces grammar
ActiveRecord validation messages are currently not I18N-friendly. Specifically, I''m referring to the fact that it enforces a certain grammar, namely the beginning of the message must consist of the field name. For example: validates_presence_of :name, :message => "can''t be blank." ...generates the message "Name can''t be blank". This grammar
2006 Jun 29
1
Newbie: Help Please - Model Validation Error
Hi, I''d be grateful for your help. I get the error (see below) everytime I add the following into a newly generated (via scaffold) model class: validates_presence_of :myname, :mymessage, :mytel Without it, I can insert records into my database. With it, I get the error :( ERROR>> ArgumentError in AdminController#create wrong number of arguments (1 for 0) RAILS_ROOT:
2010 Apr 09
0
Child to Parent Validation Errors
Hi: Passing child virtual attribute validation error to parent... in case of nested attributes. So, I have a Parent Model say ''Parent''. Nested Attributes it accepts for Child say ''Child'' Now suppose there is a validate method in ''Child'' and it has something like self.errors.add_to_base("some message"). How do you make sure that
2007 Jun 18
4
polymorphic validation
Hello I have 2 models. link.rb has_many :categories, :as => :categorized validates_presence_of :name, :url, :created_at, :category category.rb belongs_to :categorized, :polymorphic => true validates_presence_of :name Everything seems to work. I select my category from a select tag. The problem is i don''t know how to validate if category is for example empty (nothing in a
2006 Jun 21
2
Validation on update
Searched for it, but found nothing, so i open a new topic :/ I think it is very basic stuff... My model has a validation rule like this: validates_presence_of :title If i try to save the model (@mymodel.save) with an empty title-formfield i get an error. hooray! that''s what i want! okay i insert a valid title and everything is fine. now i want to update the model (@mymodel.update) and
2006 Aug 14
4
Updating a table with Ajax
I''ve been banging my head against the wall trying to update a table (add/delete rows) using Ajax. It seems simple enough but just doesn''t work for me. I can get it to work using DIVs instead of a table, but doing the layout with DIVs is much more cumbersome and I know it works for others with a table (though I haven''t been able to find an exact example code anywhere).