application_controller.rb revision 46dd7ca898be6d5dbdfda64fd90ce01e253c0878
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainenclass ApplicationController < ActionController::Base
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # CanCan Authorization
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen rescue_from CanCan::AccessDenied do |exception|
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainen redirect_to root_url, :alert => exception.message
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # A foreign key constraint exception from the database
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # shorten the message
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen :flash => {:error => "Whatever you tried to do - the server is unable to process your request because of a foreign key constraint. (#{message})" }
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # anything else
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen flash[:error] = "you need admin privileges for this action"
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen @resource_chain = [ Repository.find_by_path!( controller_name=='repositories' ? params[:id] : params[:repository_id] )]
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen if id = (controller_name=='ontologies' ? params[:id] : params[:ontology_id])
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen @resource_chain << Ontology.find(id)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen @resource_chain