module FatModelAuth
  class AuthException < Exception; end

  module ControllerHelpers
    protected

    def auth_required
      authority = get_authority

      access_granted = authority.allows(current_user).send "to_#{params[:action]}?"
      respond_with_404_page unless access_granted
    end

    def access_denied?
      authority = get_authority

      access_granted = authority.allows(current_user).send "to_#{params[:action]}?"
      if access_granted
        false
      else
        respond_with_404_page
        true
      end
    end

    private

    def get_authority
      if self.respond_to? :override_authority
        authority = override_authority
        raise FatModelAuth::AuthException, "override_authority defined but nil" if authority.nil?
      else
        authority_name = controller_name || action_name
        authority = instance_variable_get("@#{authority_name}")
        raise FatModelAuth::AuthException, "#{authority_name} is nil" if authority.nil?
      end

      return authority
    end

    def respond_with_404_page
      if defined?(Rails)
        render "#{Rails.root}/public/404.html", status: 404, layout: false
      else
        render nothing: true, status: 404, layout: false
      end
    end
  end
end

module FatModelAuth
  class AuthException < Exception; end

  module ControllerHelpers
    protected

    def auth_required
      authority = get_authority

      access_granted = authority.allows(current_user).send "to_#{params[:action]}?"
      respond_with_404_page unless access_granted
    end

    def access_denied?
      authority = get_authority

      access_granted = authority.allows(current_user).send "to_#{params[:action]}?"
      if access_granted
        false
      else
        respond_with_404_page
        true
      end
    end

    private

    def get_authority
      if self.respond_to? :override_authority
        authority = override_authority
        raise FatModelAuth::AuthException, "override_authority defined but nil" if authority.nil?
      else
        authority_name = controller_name || action_name
        authority = instance_variable_get("@#{authority_name}")
        raise FatModelAuth::AuthException, "#{authority_name} is nil" if authority.nil?
      end

      return authority
    end

    def respond_with_404_page
      if defined?(Rails)
        render file: "#{Rails.root}/public/404.html", status: 404, layout: false
      else
        render nothing: true, status: 404, layout: false
      end
    end
  end
end

Replace `render "public/404.html"` with `render file: "public/404.html"`
Replace `render "public/404.html"` with `render file: "public/404.html"`

This change is backward-compatible, so it shouldn't break existing any
existing app.

Previously, calling render "foo/bar" in a controller action was
equivalent to render file: "foo/bar". In Rails 4.2, this has been
changed to mean render template: "foo/bar" instead.

See http://guides.rubyonrails.org/4_2_release_notes.html#render-with-a-string-argument
