myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [2736] trunk/app/controllers/citations_controller


From: noreply
Subject: [myexperiment-hackers] [2736] trunk/app/controllers/citations_controller.rb: Better handling of errors (especially when workflow doesnt exist).
Date: Mon, 24 Oct 2011 11:09:16 -0400 (EDT)

Revision
2736
Author
dtm
Date
2011-10-24 11:09:16 -0400 (Mon, 24 Oct 2011)

Log Message

Better handling of errors (especially when workflow doesnt exist).

Modified Paths

Diff

Modified: trunk/app/controllers/citations_controller.rb (2735 => 2736)


--- trunk/app/controllers/citations_controller.rb	2011-10-24 12:27:56 UTC (rev 2735)
+++ trunk/app/controllers/citations_controller.rb	2011-10-24 15:09:16 UTC (rev 2736)
@@ -93,25 +93,30 @@
         @workflow.content_blob.data = "" unless Authorization.is_authorized?("download", nil, @workflow, current_user)
       else
         if logged_in?
-          error("Workflow not found (id not authorized)", "is invalid (not authorized)", :workflow_id)
+          error("Workflow not found (id not authorized)", "is invalid (not authorized)")
         else
           find_workflow_auth if login_required
         end
       end
     rescue ActiveRecord::RecordNotFound
-      error("Workflow not found", "is invalid", :workflow_id)
+      error("Workflow not found", "is invalid")
+      return false
     end
   end
   
   def find_citations
-    @citations = @workflow.citations
+    if @workflow
+      @citations = @workflow.citations
+    else
+      @citations = []
+    end
   end
   
   def find_citation
     if citation = @workflow.citations.find(:first, :conditions => ["id = ?", params[:id]])
       @citation = citation
     else
-      error("Citation not found", "is invalid")
+      error("Citation not found", "is invalid", params[:id])
     end
   end
   
@@ -119,18 +124,28 @@
     if citation = @workflow.citations.find(:first, :conditions => ["id = ? AND user_id = ?", params[:id], current_user.id])
       @citation = citation
     else
-      error("Citation not found (id not authorized)", "is invalid (not authorized)")
+      error("Citation not found (id not authorized)", "is invalid (not authorized)", params[:id])
     end
   end
   
 private
 
-  def error(notice, message, attr=:id)
+  def error(notice, message, attr=nil)
     flash[:error] = notice
-    (err = Citation.new.errors).add(attr, message)
-    
+
+    workflow_id_attr = attr
+    workflow_id_attr = :id if workflow_id_attr.nil?
+
+    (err = Citation.new.errors).add(workflow_id_attr, message)
+
     respond_to do |format|
-      format.html { redirect_to workflow_citations_url(params[:workflow_id]) }
+      format.html {
+        if attr
+          redirect_to workflow_citations_url(params[:workflow_id])
+        else
+          redirect_to workflows_url
+        end
+      }
     end
   end
   

reply via email to

[Prev in Thread] Current Thread [Next in Thread]