search is now saved asynchron and without a form which caused some redirection through searches_controller

added asynchronous save of search, removed searches_controller,
This commit is contained in:
Thomas Hille
2017-03-21 14:37:32 +01:00
parent 4a9867b81b
commit b05bb27ed9
7 changed files with 28 additions and 45 deletions

View File

@@ -6,7 +6,7 @@ class ExercisesController < ApplicationController
before_action :handle_file_uploads, only: [:create, :update]
before_action :set_execution_environments, only: [:create, :edit, :new, :update]
before_action :set_exercise, only: MEMBER_ACTIONS + [:clone, :implement, :working_times, :intervention, :run, :statistics, :submit, :reload]
before_action :set_exercise, only: MEMBER_ACTIONS + [:clone, :implement, :working_times, :intervention, :search, :run, :statistics, :submit, :reload]
before_action :set_external_user, only: [:statistics]
before_action :set_file_types, only: [:create, :edit, :new, :update]
before_action :set_course_token, only: [:implement]
@@ -223,7 +223,17 @@ class ExercisesController < ApplicationController
else
render(json: {success: 'false', error: "undefined intervention #{params[:intervention_type]}"})
end
end
def search
search_text = params[:search_text]
search = Search.new(user: current_user, exercise: @exercise, search: search_text)
begin search.save
render(json: {success: 'true'})
rescue
render(json: {success: 'false', error: "could not save search: #{$!}"})
end
end
def index

View File

@@ -1,34 +0,0 @@
class SearchesController < ApplicationController
include CommonBehavior
def authorize!
authorize(@search || @searchs)
end
private :authorize!
def create
@search = Search.new(search_params)
@search.user = current_user
authorize!
respond_to do |format|
if @search.save
path = implement_exercise_path(@search.exercise)
respond_with_valid_object(format, path: path, status: :created)
end
end
end
def search_params
params[:search].permit(:search, :exercise_id)
end
private :search_params
def index
@search = policy_scope(ProxyExercise).search(params[:q])
@searches = @search.result.order(:title).paginate(page: params[:page])
authorize!
end
end