From 90ea5257140526ebd49173ff503cf9290dbdd88e Mon Sep 17 00:00:00 2001 From: brchristian Date: Fri, 15 Nov 2013 15:04:20 -0800 Subject: [PATCH] Include error messages in create failure flash I was struggling with an article that was failing to save for unknown reasons. Rather than having to inspect the logs or insert `binding.pry` calls, I thought it might be handy if the error message itself returned the relevant error messages. Here's a proposal for code which would provide that helpful information to Casein users. --- lib/generators/casein/scaffold/templates/controller.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/generators/casein/scaffold/templates/controller.rb b/lib/generators/casein/scaffold/templates/controller.rb index fbf75af..11ceae1 100644 --- a/lib/generators/casein/scaffold/templates/controller.rb +++ b/lib/generators/casein/scaffold/templates/controller.rb @@ -29,7 +29,11 @@ def create flash[:notice] = '<%= singular_name.humanize.capitalize %> created' redirect_to casein_<%= @plural_route %>_path else - flash.now[:warning] = 'There were problems when trying to create a new <%= singular_name.humanize.downcase %>' + warning_msg = "There were problems when trying to create a new<%= singular_name.humanize.downcase %>" + if @<%= singular_name %>.errors + warning_msg += ': "' + @<%= singular_name %>.errors.full_messages.join(' ') + '"' + end + flash.now[:warning] = warning_msg render :action => :new end end @@ -57,4 +61,4 @@ def destroy end end -end \ No newline at end of file +end