similar to: Problems with before_validation

Displaying 20 results from an estimated 2000 matches similar to: "Problems with before_validation"

2011 Jun 19
1
before before_validation callback
Hi, I was looking around a bit and couldn''t find any callbacks that executed before before_validation The current problem with using before_validation is that it won''t fire if I''m not using validations with #save(:validate => false) - which makes sense. Before_save won''t suffice because I want these callbacks to fire before validation on the occasions that
2012 May 26
2
before_create is after_validatation :on => :create , when it should be before_validation :on => :create
In ActiveRecord''s callbacks, methods within a before_create callback are called after the validation, but before the model is created. This was an intentional design decision, but I think it was the wrong one. What do you think? When I think of before_create, I think of before_validation :foo, :on => :create, but, by default, before_create is synonymous with after_validation :foo,
2007 Apr 05
0
unexpected behavior of before_validation
Today I found these comments in active record''s callbacks.rb file: # If the returning value of a before_validation callback can be evaluated to false, the process will be aborted and Base#save will return false. # If Base#save! is called it will raise a RecordNotSave error. # Nothing will be appended to the errors object. This caused me a lot of frustration earlier when I was
2006 Jul 28
3
Forms: handle foreign keys (AssociationTypeMismatch)
Hi all I tried and tried and tried, but I still fail in creating a form with proper validation and stuff for foreign keys... So I''d really like to get some help here. I''m creating a booking site for DJ''s, and for every booking one can choose one of different countries: class Booking < ActiveRecord::Base validates_presence_of :country_id
2006 Mar 25
0
[Sentry]-before_validation(model) not working for crypted-attribute?
I am still trying to get sentry working to encrypt a couple of attributes in the model. One of them is a password field and the other ssn#. I have crypted_password and crypted_ssn in the db. In addition, I also have validates_uniqueness_of :ssn Here is the problem... I get the error MysqlError: Unknown column ''ssn'' in ''where clause'': SELECT * FROM students
2009 Jun 24
2
At my wits end ! Controlling passed in negative values from a form
Hi, I am trying to validate a numeric value passed in from a form, which is saved in a MySQL db as decimal(9,2) Now problem is I need to ensure people don''t enter a form value like -. 003. In my validations, I have a validates_numericality_of check being done. Furthermore, in validate method, I have a check using an if statement such as : ((an_object[n].nil? or an_object[n] < 0) and
2005 Mar 01
0
has_and_belongs_to_many problem
I''m having a problem with a has_and_belongs_to_many (habtm) association between two models with extra attributes. I''m writing a comic book database, and each issue has many creators on it. Thing is, some creators perform multiple duties. They may write one issue, draw another, etc. However, if I add a creator twice to an issue and try to delete it, it removes both creators:
2006 Apr 27
3
Removing a default value for a foreign key with not null set
Hi all, For various reasons I need to have foreign keys with not null constraints. Eg: create_table :people do |t| t.column :name, :string t.column :household_id, :integer, :null => false end create_table :households do |t| t.column :name, :string end add_foreign_key_constraint :people, :household_id, :households, :id So the people table has a foreign key into
2006 Mar 24
1
validates... :if => Proc.new{...} does not find a method!
Hi all I wanted to use the following validation in my model Party: validates_presence_of :organisator_name, :if => Proc.new{ member.organisators.empty? } I have written the member method in the ApplicationController: class ApplicationController < ActionController::Base def member session[:member] end end But it does not seem to be known by the Party
2006 Apr 06
4
using two foreign keys to the same table
i am working on a task manager with ruby on rails. it is my first major project, so i''m still gettng my feet wet as i learn. i''ve been trying to use the built in relationships to link my tables together, but i''m not able to use the same naming conventions. for each task, it has a field for the creator, and another field for the assignee. both of these fields
2012 Nov 10
6
Suggestion: `before_save on: :create` should either work or raise an exception
There''s a small inconsistency in ActiveRecord''s callback syntax that has tripped me up before. It wouldn''t be a big deal, but it can lead to a silent failure. I''d like to suggest that it either be made consistent or be made to fail loudly. The issue is that to do something before validating, but only when creating, you use `before_validation on: :create`,
2006 Nov 10
3
Move variables from session to ActiveRecord?
Buildings have units. Units have rooms. Rooms have people. I can grab building, room, and people IDs and store them in a session[:variable]. However, when creating a new unit, I need to give that session[:building_id] to ActiveRecord for creation. I''m not sure whether to use hidden fields or do it all in the model ''before_validation'' - in either case I
2006 May 02
4
useful bit of code (hopefully)
Hi, I often find myself using bits of code like this inside ActiveRecord, perhaps it''s useful for others, or others can improve on it: ########### # fix user input before validating it before_validation :sanitize_input # santize input before actual validation is called # this uses the little methods defined below def sanitize_input trim %w(adres postcode woonplaats email naam
2006 Apr 01
5
Upload a zip using a form and extract if afterwards on srv?
Hi all It like my visitors to be able to upload a zip file (or any other possible compressed file archive) to my server. After upload, my web app should extract the content to the server and delete the zip file. Is this possible somehow? I''m very thankful for help. Have a nice weekend, Joshua -- Posted via http://www.ruby-forum.com/.
2008 Jan 14
2
simple syntax question (models, validation)
who can explain this to me? def before_validation logger.info url url = "http://" << url if url[0..3]=="www." end the logger line correctly logs any URL that''s been submitted, let''s say it''s "www.amazon.co.uk" BUT Rails raises an exception on the next line, complaining about nil. [] (obviously from the url[0..3] bit) It works
2006 Jul 14
3
Migration not updating fields
So I have this fairly basic migration bit of code class AddCounterCache < ActiveRecord::Migration def self.up add_column ''products'', ''backlog_items_count'', :integer, :default => 0 end def self.down remove_column ''products'', ''backlog_items_count'' end end What I want to do in that is automatically
2008 Apr 17
1
Callback Problem: Why to use self.var= instead of @var=
Hi, I''ve defined the following model: class Eintrag < ActiveRecord::Base before_validation :vali protected def vali # self.feld1.reverse! self.feld2 = self.feld1 end end Now I''m wondering why I have to write self.feld2=self.feld1 and why @feld2=@feld1 doesn''t work. I''ve found the thread
2005 Apr 04
1
Validation problems: ActiveRecord::AssociationTypeMismatch
Hi everyone, I''m starting on my first rails project and I have a problem that I''m sure has a simple solution. I have two models, an address model and a state model. The address belongs_to :state, foreign_key=>"state" and validate_associated :state I have new & edit controllers for address which contain a drop down list for the state choice. My list was
2006 Dec 11
1
Compute date during before_validation_on_create
Hello, - the form posted by the user have a date field - this date is begin_date, I need to compute end_date - so, added callback before_validation_on_create - in this method I do : end_date = begin_date >> 12 - unfortunately, beeing in before_validation the actual self.begin_date have not been type casted - It''s always a string - unfortunately again, I can''t put this code
2006 Feb 01
1
Bus error when running Hieraki
I have been trying to set up Hieraki 2.0.1 and I cannot seem to get it running. I am running on FreeBSD 5.4, Ruby 1.8.4, Apache 2.0.55, Mysql 4.1.16, ruby-mysql 2.7, mod_scgi 1.9, scgi_rails 4.3 and Rails 1.0. I can start up the wiki, get it to display the home page, and when I click on the signup link the signup form displays. When I fill in the signup form and click the signup button, the