Merge remote-tracking branch 'origin/master' into 2042-new-collection-from-selected...
[arvados.git] / apps / workbench / app / controllers / application_controller.rb
index cc452b93cbf6b3c4dfceac5bc533b6a2523038cf..2790f96472f0cac1633340465bc8524bf20f6940 100644 (file)
@@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base
   around_filter :thread_clear
   around_filter :thread_with_mandatory_api_token, :except => [:render_exception, :render_not_found]
   around_filter :thread_with_optional_api_token
-  before_filter :find_object_by_uuid, :except => [:index, :render_exception, :render_not_found]
+  before_filter :find_object_by_uuid, :except => [:index, :post, :render_exception, :render_not_found]
   before_filter :check_user_agreements, :except => [:render_exception, :render_not_found]
   before_filter :check_user_notifications, :except => [:render_exception, :render_not_found]
   theme :select_theme
@@ -24,6 +24,7 @@ class ApplicationController < ActionController::Base
 
   def unprocessable(message=nil)
     @errors ||= []
+
     @errors << message if message
     render_error status: 422
   end
@@ -57,7 +58,7 @@ class ApplicationController < ActionController::Base
   end
 
   def index
-    @objects ||= model_class.limit(1000).all
+    @objects ||= model_class.limit(200).all
     respond_to do |f|
       f.json { render json: @objects }
       f.html { render }
@@ -107,14 +108,22 @@ class ApplicationController < ActionController::Base
   end
 
   def create
-    @object ||= model_class.new params[model_class.to_s.singularize.to_sym]
+    @object ||= model_class.new params[model_class.to_s.underscore.singularize]
     @object.save!
-    redirect_to(params[:return_to] || @object)
+
+    respond_to do |f|
+      f.json { render json: @object }
+      f.html {
+        redirect_to(params[:return_to] || @object)
+      }
+      f.js { render }
+    end
   end
 
   def destroy
     if @object.destroy
       respond_to do |f|
+        f.json { render json: @object }
         f.html {
           redirect_to(params[:return_to] || :back)
         }