search for: validate_on_update

Displaying 20 results from an estimated 23 matches for "validate_on_update".

2007 Jun 08
1
Acessing new field values in validate_on_update
Hello, How to access to old field values in validate_on_update method? I need to see if there is changed field''s value and if it is so, rise an error. Thank you! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group...
2006 Apr 14
1
Validating Existing Models
...occur. I want it to validate, but ONLY certain things. For example, I dont want it to validate the username uniqueness on an update, or the email uniqueness if the user didn''t try to change it (but DO want to if they did change it). Is there a way to specify different rules using the validate_on_update overriding method or something similar? The docs on validate_on_update seem kind of slim so I''m not exactly sure how to implement this conditional validation. -- Posted via http://www.ruby-forum.com/.
2007 May 23
6
RESTful RESOURCE PARTIAL UPDATE
I have modified scaffolding code slightly to get three edit actions and three update actions. The requirement: to allow users to edit attributes for the same model from seperate forms instead of one form, while using the given scaffolding code and performing model validations. I am using restful_authentication with the login email password validations defined. class users_controller
2006 Mar 13
3
validates_associated problem
...''department'' and have setup the relationship as follows. class Employee < ActiveRecord::Base belongs_to :department, :foregin_key => "department_id" validates_associated :department_id end class Department < ActiveRecord::Base has_many :employees def validate_on_update unless self.find_by_id(id) error.add(:id, "is invalid department") end end However when I try to save an employee with some test department ''578'', get the following error because of validates_associated in employee "undefined method `valid?'' for &...
2006 Apr 25
14
validate_on_update with a save()
...ts like user[first_name], user[last_name], etc. When editing the user instead of creating a new one I include a user[id]. I then try and save the object using: user = User.new(params[:user]) user.save() I would *expect* that since I included the user[id] it should do an update and should call validate_on_update. But this doesn''t appear to be the case. When I call the save it runs the code in validate_on_create instead (which fails validation). Why is this? -- Posted via http://www.ruby-forum.com/.
2006 Dec 07
2
validate_on_destroy ?
What''s the best way to validate_on_destroy. Rails only seems to include validate_on_create and validate_on_update methods. I don''t want to resort to doing: before_destroy do |j| raise "There is an error" if j.etc end Is there a way of finding out what action (create/update/destroy) is being performed if I use the ''validate'' method? -- Posted via http://www.ruby-forum.com...
2006 Feb 03
2
validation only on a specific action
Hello again! I have a action that lists users and that allows an admin user to create new users. When the admin user creates a new user an e-mail is sent to the created user telling him to register in the site. I want to validate the user name and password only when the user register and not when the admin user creates it. Can anyone tell me how to do this? Thanks. Best regards, Hugo --
2005 Sep 27
2
No Custom Validation
Hi, Correct me if I am wrong but there doesn''t seem to be an easy way to add validation outside the pre-built ones (validates_presence_of, validates_lenght_of, etc.). Ideally there should be something like: Class Person < ActiveRecord::Base validates :my_method, :on => create, :message => ''was not valid'' def my_method(param) false unless
2006 Mar 06
4
One-way change
I''m developing an app, and I want to make a single boolean field OK to change from 0 to 1, but not allow 1 to 0. Seems like the model''s validate method would be the right place for this, but I''m not sure how to implement it. Any suggestions (actual or pointers to) are greatly appreciated. -- Posted via http://www.ruby-forum.com/.
2009 Dec 30
4
Validating the presence of two associated objects from both models
...odel, however, Conversations can no longer be saved on creation because the Leader model is invalid. On creation of both a new Conversation and new Leader how can I validate in each model that it is associated with the other? Is there a best practice? The closest I’ve come is to override Leader’s “validate_on_update” method to ensure the presence of a Conversation but that still allows new Leader objects to be created without a Conversation, filling my tables with junk. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, s...
2006 Jan 19
2
Easy way to handle form input without a model class?
I have a couple forms that I''d like to be able to validate and automatically populate, but it shouldn''t be based on AR. In fact I often have a bunch of small forms that I can''t really justify writing a whole new model class for anyway. I''d like to validate the form input, and then use rails helpers to automatically populate the form if validations fail.
2006 Jun 19
2
call validate functions
Hi on the code below the validates all the form fields if @client.save flash[:notice] = ''Client was successfully created.'' redirect_to :action => ''list'' else render :action => ''new'' end how can I do this action without having to save the object? ie if validate #move on to next stage else redner
2006 Jun 25
0
Using the database schema to help validate data
...of :title, :maximum => 5 Index: lib/active_record/validations.rb =================================================================== --- lib/active_record/validations.rb (revision 4491) +++ lib/active_record/validations.rb (working copy) @@ -250,6 +250,21 @@ write_inheritable_set(:validate_on_update, methods) end + def validates_database_schema() + columns.each {|column| + column.primary = column.name == primary_key + # Setup default validation for text columns + if column.text? then + # varchars have a limit, while text columns general...
2006 Mar 02
3
validates_uniqeness_of
Hello, I am trying to understand usage of validates_uniqeness_of. Say I have, two column ''name'' and ''email'' in my table users three unique key is possible for these two columns 1. name 2. email 3. name and email together My question is, if I write validates_uniqueness_of :name, :email what uniqueness is it going to apply, 1 and 2 or, 3 ? Thanks, Mohammad
2006 Feb 28
1
Validate two fields so they do not match
Hey all, I have two form fields (select dropdowns) that are ''startlocation'' and ''endlocation''. These two cannot be equal to each other on save and I am wondering how to put validation into the model for this. Is is possible to do it in the model, or do I need to do this in the controller? Thanks in advance! Ryan -- Ryan Prins rprins@gmail.com
2011 Apr 28
3
difference between validate and validate_on_create
i just ran into a problem with some test, and i am not exactly sure why, but the difference happened when i changed my model validation from: validate :custom_validation to: validate_on_create :custom_validation can someone give me any ideas on where in the chain the validation takes place? thanks! -- Posted via http://www.ruby-forum.com/.
2007 Aug 02
1
write_attribute functionality for related objects?
Hi. Given: class Group < AR has_many :users end Is it in any way possible to retain reference to the old users when they get replaced using group.users=(new_users) ? The below doesn''t work but illustrates what I''m looking for: class Group < AR has_many :users def users=(new_users) @old_users = users write_attribute(''users'', new_users)
2008 Feb 03
1
ActiveRecord object.valid? triggers unexepected results
...m, I want to save them all together. The surprise was that object.valid? triggers after_validation_on_update. I''m having an audit log and I was getting bogus entries. http://api.rubyonrails.org/classes/ActiveRecord/Validations.html#M001316 valid?() Runs validate and validate_on_create or validate_on_update and returns true if no errors were added otherwise false. valid?() should run all validations, but not trigger after_validation callbacks. This is not just a rant... I''m looking for solutions? How can I have an audit log on updates and running valid()? without polluting my audit log? --...
2006 Dec 11
2
Custom Validator
I want to add a custom validator in one of Model. For example Rails has inbuilt validation methods like validates_uniqueness_of, validates_presence_of . What I need is a similar kind of method (example: validates_line_items), that can run my custom code while saving, updating the record and can add custom error messages to the record. Please help me by suggesting how i can do this. -- Posted via
2006 May 12
4
validates_uniqueness_of with a condition
Hi, I need to check the uniqueness of an attribute (a doc number) using a condition (a specific year), I''ve found validates_uniqueness_of :number, but I need to tell it I just want to check a specific year. I''ve found :scope but I haven''t really understood it''s meaning, Can I scope on a specific year? Thanks, Enrico -- "The only thing necessary for the