views:

17

answers:

1

Hi. I have a model in Rails 3. When creating the record, there are a total of 3 columns for the model.

Right now, Rails allows for creating a record if only 2 of the 3 records are populated?

In rails, how do you tell Rails only create a record if 3 values for each column exist when creating?

thank you

+1  A: 
class Person < ActiveRecord::Base
  validates_presence_of :name, :login, :email
end

http://guides.rubyonrails.org/active_record_validations_callbacks.html#validates_presence_of

動靜能量
Interesting. So that worked from preventing the record from being created. BUT it isn't triggering an error. " respond_to do |format| if @mymodel.save" stillgoes through?
I think Rails 3 is like Rails 2, when it doesn't validate, it will go back to the form stating the error, and can even have the invalid field highlighted.
動靜能量