On 11/04/2010 05:46 AM, Jan Provaznik wrote:
On 11/03/2010 08:50 PM, Mohammed Morsi wrote:
Also limits template name to standard db varchar length of 255 characters. Eventually all the other db string fields should have this validation
src/app/controllers/templates_controller.rb | 6 ++++-- src/app/models/template.rb | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/app/controllers/templates_controller.rb b/src/app/controllers/templates_controller.rb index 3373c05..f9eaf5e 100644 --- a/src/app/controllers/templates_controller.rb +++ b/src/app/controllers/templates_controller.rb @@ -106,11 +106,13 @@ class TemplatesController< ApplicationController # synchronize it at first to xml @tpl.update_xml_attributes(params[:tpl])
- if @tpl.save
- begin
@tpl.save! flash[:notice] = "Template saved." @tpl.set_complete redirect_to :action => 'index'
- else
- rescue Exception => e
flash[:notice] = "There was a problem saving the template:
#{e.to_s}" get_selected_packages(@tpl) render :action => 'new' end diff --git a/src/app/models/template.rb b/src/app/models/template.rb index 9264e76..e9f2327 100644 --- a/src/app/models/template.rb +++ b/src/app/models/template.rb @@ -14,6 +14,7 @@ class Template< ActiveRecord::Base # unset) validates_presence_of :name validates_uniqueness_of :name
- validates_length_of :name, :maximum => 255 validates_presence_of :platform validates_presence_of :platform_version validates_presence_of :architecture
Hi, I think we should keep 'save' instead of 'save!'. Errors are already printed by error_messages_for, so with this exception catching it's printed twice. As you suggested, we should add validation_length for all string attrs.
Jan
Good point. I did this all at once before testing it, and had forgot the form's error_messages_for should take care of reporting the validation error. Thanks alot, updated patch resent.
-Mo