Class: PapertrailController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- PapertrailController
- Defined in:
- app/controllers/papertrail_controller.rb
Instance Method Summary collapse
- #compare ⇒ Object
- #compare_params ⇒ Object protected
-
#papertrail ⇒ Object
GET /papertrail.
- #show ⇒ Object
- #update ⇒ Object
Methods included from RequestType
Methods included from LogRecent
Methods included from Cookies
#digest_cookie, #digested_cookie_exists?
Methods included from Whitelist
Methods included from ProjectsHelper
#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form
Methods included from Api::Intercept
Methods included from TokenAuthentication
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#compare ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/controllers/papertrail_controller.rb', line 63 def compare klass = whitelist_constantize(params.require(:object_type)) @object = klass.find(params.require(:object_id)) if invalid_object(@object) record_not_found else @result = TaxonWorks::Vendor::Papertrail.compare(@object, compare_params) @result ? render('compare') : record_not_found end end |
#compare_params ⇒ Object (protected)
77 78 79 |
# File 'app/controllers/papertrail_controller.rb', line 77 def compare_params params.permit(:version_a, :version_b) end |
#papertrail ⇒ Object
GET /papertrail
5 6 7 8 9 10 |
# File 'app/controllers/papertrail_controller.rb', line 5 def papertrail redirect_to hub_path, notice: 'You requested a papertrail for nothing.' and return if params[:object_type].blank? klass = whitelist_constantize(params.require(:object_type)) @object = klass.find(params[:object_id]) record_not_found if invalid_object(@object) end |
#show ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/papertrail_controller.rb', line 12 def show @version = PaperTrail::Version.find(params[:id]) @object = @version.item if invalid_object(@object) record_not_found else render 'papertrail' end end |
#update ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/papertrail_controller.rb', line 22 def update klass = whitelist_constantize(params.require(:object_type)) @object = klass.find(params[:object_id]) if invalid_object(@object) record_not_found else new_attributes = params[:attributes] if !new_attributes.nil? new_attributes.each do |key, value| if @object.has_attribute?(key) @object.assign_attributes(Hash[key, value]) end end end if !@object.changed? flash[:notice] = 'No changes made!' elsif @object.save flash[:notice] = 'Successfully restored!' else flash[:alert] = 'Unsuccessfully restored!' end json_resp = { "url": papertrail_path(object_type: @object.class.base_class, object_id: @object.id) } # If the object is a child class of "ControlledVocabularyTerm" then we need to use the # type member variable since the class member variable doesn't reflect the new class # yet and the type is the correct one thus the link thats generated will be correct if ControlledVocabularyTerm > @object.class json_resp['url'] = papertrail_path(object_type: @object.type, object_id: @object.id) end respond_to do |format| format.html { redirect_to(papertrail_path(object_type: @object.type, object_id: @object.id)) } format.json { render json: json_resp } end end end |