I check for
validates :group_id, :presence => true
in my 开发者_如何学JAVAmodel "project". Yet when I create a project without a group_id, I don't get a validation-error. If I try to do
p = Project(:name => "Test")
p.save
the rails console returns false, with save! it tells me the validation for group_id failed. So the validation is somehow performed on the save method, yet it isn't by default in my app. Do I have to do a manual
if @project.save == true
...
end
or something in my controller?
Thank you, B
You can check @project.valid? before save.
def signup
if request.post?
@user_data = UserData.new(:login => params[:user], :password => params[:password])
if @user_data.valid?
if @user_data.save
session[:cuser] = UserData.authenticate(@user_data.login, @user_data.password).login
redirect_to(:controller=> 'sync', :action=> 'all')
return
end
else
@error_on_signup = true
end
end
精彩评论