Class: MarkAsRead::MarkAsReadController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/mark_as_read/mark_as_read_controller.rb

Instance Method Summary collapse

Instance Method Details

#readObject

Raises:



4
5
6
7
8
9
10
11
12
13
14
# File 'app/controllers/mark_as_read/mark_as_read_controller.rb', line 4

def read
  verifier = ActiveSupport::MessageVerifier.new(Rails.application.config.secret_key_base)
  type = params[:type].constantize rescue nil
  raise UnknownType.new("No such type: #{type}") unless type
  raise InvalidType.new("Type #{type} is not a valid model type") unless type.respond_to?(:find)

  model = type.find(verifier.verify(params[:id]))
  raise InvalidType.new("Type #{type} does not include mark_as_read") unless model.respond_to?(:mark_as_read!)
  model.mark_as_read!
  send_data(Base64.decode64("R0lGODlhAQABAPAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="), :type => "image/gif", :disposition => "inline")
end