diff --git a/app/controllers/complaints_controller.rb b/app/controllers/complaints_controller.rb index 26f48b71b69f57068c1b3993cd63448285fb726d..bb1bc86bd4ea1853ad0f305c76b5d8dba73e6a3b 100644 --- a/app/controllers/complaints_controller.rb +++ b/app/controllers/complaints_controller.rb @@ -6,8 +6,8 @@ class ComplaintsController < ApplicationController def create @complaint = Complaint.new(complaint_params) @complaint.user = current_user - @complaint.object = params[:object] - + @complaint.object = params[:complaint][:object_rid] + respond_to do |format| if complaint_repository.report @complaint format.html { redirect_to @complaint, notice: 'complaint was successfully created.' } diff --git a/app/repositories/orient_db/complaint_repository.rb b/app/repositories/orient_db/complaint_repository.rb index 58dd7de100e440ee002d33805c1ca8eef726d650..416b6462dff4d3bd7612a9d562127f287fe12bcc 100644 --- a/app/repositories/orient_db/complaint_repository.rb +++ b/app/repositories/orient_db/complaint_repository.rb @@ -4,19 +4,18 @@ module OrientDb include RepositoriesProxy def report(complaint) - if edge_exists?(odb_class, complaint.user.id, complaint.object.id) - raise "The user has already been reported" + if edge_exists?(odb_class, complaint.user.rid, complaint.object) + raise "The object has already been reported by you." end - - connection.command "CREATE EDGE Complaint FROM #{complaint.user.id} TO #{complaint.object.id} SET message = #{complaint.message}, description = #{complaint.description}" + connection.command "CREATE EDGE Complaint FROM #{complaint.user.rid} TO #{complaint.object} SET message = #{complaint.message}, description = #{complaint.description}" end def destroy(object) - if !edge_exists?(odb_class, complaint.user.id, complaint.object.id) - raise "The user has not already been reported" + if !edge_exists?(odb_class, complaint.user.rid, complaint.object) + raise "The object has not been reported by you yet." end - connection.command "DELETE EDGE Complaint FROM #{complaint.user.id} TO #{complaint.object.id}" + connection.command "DELETE EDGE Complaint FROM #{complaint.user.rid} TO #{complaint.object}" end def build_object(args={}) diff --git a/app/views/complaints/_form.html.erb b/app/views/complaints/_form.html.erb index 6abcde32db89ce3e4cf52d80d6ec781500893bef..aef72f5ba0d1e54727bbcb5bc4c6aa1a6a839479 100644 --- a/app/views/complaints/_form.html.erb +++ b/app/views/complaints/_form.html.erb @@ -21,7 +21,7 @@ </div> - <%= f.hidden_field :object, value: @learning_object %> + <%= f.hidden_field :object_rid, value: @learning_object.id %> </fieldset> <div align="center" class="ls-btn-primary">