Class: Avo::ActionsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Avo::ActionsController
- Defined in:
- app/controllers/avo/actions_controller.rb
Instance Method Summary collapse
- #build_background_url ⇒ Object
- #handle ⇒ Object
-
#set_record ⇒ Object
Sets @record based on context: - If we're on a show page (with an :id param), defer to superclass logic - If on an index page with exactly one query result, assign it directly.
- #show ⇒ Object
Instance Method Details
#build_background_url ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/avo/actions_controller.rb', line 30 def build_background_url uri = URI.parse(request.url) # Remove the "/actions" segment from the path path_without_actions = uri.path.sub("/actions", "") params = URI.decode_www_form(uri.query || "").to_h params.delete("action_id") params[:turbo_frame] = ACTIONS_BACKGROUND_FRAME_ID # Reconstruct the query string new_query_string = URI.encode_www_form(params) # Update the URI components uri.path = path_without_actions uri.query = (new_query_string == "") ? nil : new_query_string # Reconstruct the modified URL @background_url = uri.to_s end |
#handle ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/controllers/avo/actions_controller.rb', line 52 def handle performed_action = @action.handle_action( fields: @fields, current_user: _current_user, resource: @resource, query: @query, request: request ) @response = performed_action.response respond end |
#set_record ⇒ Object
Sets @record based on context:
- If we're on a show page (with an :id param), defer to superclass logic
- If on an index page with exactly one query result, assign it directly
10 11 12 13 14 15 16 |
# File 'app/controllers/avo/actions_controller.rb', line 10 def set_record if params[:id].present? super elsif @query.size == 1 @record = @query.first end end |
#show ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/avo/actions_controller.rb', line 20 def show # Se the view to :new so the default value gets prefilled @view = Avo::ViewInquirer.new("new") @resource.hydrate(record: @record, view: @view, user: _current_user, params: params) @fields = @action.get_fields build_background_url end |