Class: Relay::Routes::UploadAttachment

Inherits:
Base
  • Object
show all
Includes:
Hooks::RequireUser
Defined in:
app/routes/upload_attachment.rb

Instance Method Summary collapse

Methods inherited from Base

#cache, #htmx?, #params, #root

Methods included from Concerns::View

#cancellable?, #context_window, #format_cost, #format_name, #initials, #markdown, #status_bar

Methods included from Concerns::Roda

#initialize, #method_missing, #r, #respond_to_missing?

Methods included from Concerns::Context

#contexts, #ctx, #current_context, #default_context, #default_model, #llm, #llms, #mcps, #model, #models, #normalize_model, #provider, #sync_context!, #user, #valid_model?

Methods included from Concerns::Attachment

#attachment

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Relay::Concerns::Roda

Instance Method Details

#callObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/routes/upload_attachment.rb', line 9

def call
  raise ArgumentError, attachment.unsupported_message unless attachment.type_supported?(filename:, type:)
  attachment.attach(io: request.body, filename:, type:)
  response.status = 200
  response["content-type"] = "text/html"
  partial("fragments/input", locals: {swap_oob: false})
rescue ArgumentError => e
  attachment.error = e.message
  response.status = 422
  response["content-type"] = "text/html"
  partial("fragments/input", locals: {swap_oob: false})
end