similar to: nulls changing to blanks

Displaying 20 results from an estimated 60000 matches similar to: "nulls changing to blanks"

2006 Jan 30
9
Something as after_successful_validation?
I need to call callback only if the validation was successful, but it seems it is called also when validation fails. -- Posted via http://www.ruby-forum.com/.
2006 Nov 17
4
set empty values as null in the database
Le''s say that I have a table called people and the column middle_name is nullable. If the user enters say blank or empty space then in the database it is recorded as empty space. I would like in all my models all empty spaces to be recorded as null. I guess I can write a plugin which will do so for all the models but I''m sure something like that should already be existing.I
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 May 08
8
enforcing special behavior of child rows in HABTM
Hi, I have a scenario where a doctor can have one or more specialties. For each doctor, one and only one of her specialties can be designated as primary. So I have tables called doctors, specialties, and doctors_specialties, the last of which has a boolean is_primary column. The doctor model class specifies that: has_and_belongs_to_many :specialties I want to enforce, at the lowest possible
2008 Jun 20
15
before_save model callback rspec testing
hi all, i''m learning rspec and i can''t figure out how to test if a callback is executed in a model. my model code is: class User < ActiveRecord::Base before_save :encrypt_password ... def encrypt(password) self.class.encrypt(password, salt) end thanks a lot, cs. -- Posted via http://www.ruby-forum.com/.
2006 Mar 13
6
noob question!! auto fill forms
I''ve been using rails for about 3 months and have a pretty cool app going, but i need to auto-fill some form data. is this possible? i would think so. well anybody to lend me a helping hand, much appreciated. -- Posted via http://www.ruby-forum.com/.
2005 Dec 18
13
calculate age based on DoB
Hi, I wrote a little helper that calulates someone''s age based on his/her date of birth. def age(dob) diff = Date.today - dob age = (diff / 365.25).floor age.to_s end It works fine, but it''s not completely accurate as it just takes the average days in a year. It should be able to calculate this more accurately, right? I can''t work it out
2009 Mar 17
4
Preventing a submitted hash from ActiveRecord DB store
Hi all, I have a multi model form (Project with many tasks) and I want to prevent a task from being saved to the DB if it is empty ie. if there is no i/p for that task from the user. I tried the following class Task < ActiveRecord::Base before_save :check_if_empty ... def check_if_empty self.destroy if description.blank? end but i get this TypeError in ProjectsController#create
2006 Mar 10
19
validates_date plugin for ActiveRecord
This plugin gives ActiveRecord the ability to do stricter date checking. Example: class Person < ActiveRecord::Base validates_date :date_of_birth end This will ensure that date_of_birth is a *valid* date. The date can be set initially as a string in any of the following formats: "2006-01-01" "1 Jan 06", or "1 Jan 2006" "1/1/06" # Day /
2006 Jun 27
4
Not Active Record Model Validation
I have a problem with ruby on rails validation total_book_toy.rhtml ================ <%= text_field ''book1'', ''title1'' %> <%= text_field ''book2'', ''title2'' %> I want to validate these text_field so user can''t insert same title. However, I was stuck how to do it. Or maybe you have another way how to do it.
2007 Aug 29
2
new to rails, quick (hopefully simple) question
I am brand new to rails and I am attempting to make my first web app. I have quickly run into my first problem however that I can''t seem to get by. It seems like it would be easy to get around (with my knowledge of other languages besides ruby), but I can''t seem to get by it. Right now, I have a note model that contains attributes, :title (string) :content (text) and :tags
2005 Dec 20
2
Null Text Fields
I tend to allow nulls in cases where the value is unknown, even if it''s a text/varchar field. RoR seems to push empty strings into these fields. Is there any way to get RoR to use NULL vice '''' if the input box is empty? Thanks! - Ian
2006 Mar 03
6
has_one :next - invalid name?
I have this in a model: has_one :next, :class_name=>''WorkPart'', :foreign_key=>''next_id'' And it causes this error: compile error /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/deprecated_associations.rb:83: void value expression
2005 Dec 14
4
newbie q: Form element focus
This is probably a dumb question, but is there an easy way to set the focus of a form to the first visible/editable element? I''ve been googling lots and searching documentation and haven''t come up with anything. Help would be appreciated. -- Posted via http://www.ruby-forum.com/.
2006 Jun 15
4
parse only seem to understand US date format
I''ve tried Time.parse() and DateTime.parse() but they interpret the date as US format. Is there any way to tell it to interpret as dd/mm/yyyy? -- Posted via http://www.ruby-forum.com/.
2006 Mar 14
7
Overriding new or create for a model
I have a model where I need to calculate one of the fields when I create a new instance. It seems to me that I should do this in the model code and that I should override the new and/or create methods. Is this the right approach and, if so, how can I execute the existing method but add on my calculation? I want something like: def create -Do the original create first- field =
2006 Jun 21
8
Modifying Model Output
Hi! I''m a very-very new Ruby-on-Rails user even if I have some experience with other Languages (mostly PHP, so this is my first real object-oriented language) My problem, newbie-ish as it is, is the following: I have a model, Article, that returns Articles from the DB. Now, when a certain field of the model (the intro text) contains no data, I want to fill it with a truncated
2006 Apr 01
4
Custom Validations
Does anyone how to create a validation that: validates_presence_of :a OR :b I.e. :a OR :b must be present. I thought this would probably be possible with some kind of validation callback, e.g.: def check_a_or_b_is_set return (a or b) end Any ideas? Thanks, Rob -------------- next part -------------- An HTML attachment was scrubbed... URL:
2006 Jul 27
25
Why are has_one objects resaved when the parent is saved?
If the associated object of a has_one association has been loaded, it is resaved when the parent is saved. Eg: class Person < ActiveRecord::Base has_one :user end class User < ActiveRecord::Base belongs_to :person end p = Person.find(:first) p.save # As expected, nothing happens with the user association p.user # Loads the associated object p.save # As well as saving the person, the
2006 May 10
13
Issue in ActiveRecord generated reader methods
Hi all! I have come into a strange issue in Rails that I am hoping someone can shed some light. To make a very long story short, I have been researching how to override ActiveRecord::Base#read_attribute and write_attribute to perform security checks at the model level (influenced by the ModelSecurity generator). Shortly after implementing some code to check this behavior, I began to