Module: RubyCms::AdminTurboTable
- Extended by:
- ActiveSupport::Concern
- Included in:
- RubyCms::Admin::ContentBlocksController, RubyCms::Admin::PermissionsController, RubyCms::Admin::UsersController, RubyCms::Admin::VisitorErrorsController
- Defined in:
- app/controllers/concerns/ruby_cms/admin_turbo_table.rb
Instance Method Summary collapse
-
#turbo_frame_id ⇒ String?
Get Turbo Frame ID from request.
-
#turbo_frame_request? ⇒ Boolean
Check if this is a Turbo Frame request.
-
#turbo_redirect_to(url) ⇒ Object
Redirect with Turbo Frame support If Turbo Frame request, renders Turbo Stream redirect Otherwise performs normal redirect.
-
#turbo_render_index(turbo_frame_id: "admin_table_content") ⇒ Object
Render index action with Turbo Frame support If Turbo Frame request, renders only the table content Otherwise renders full page.
-
#turbo_stream_replace_table(turbo_frame_id: "admin_table_content", partial: nil) ⇒ Object
Render Turbo Stream replace for table.
-
#turbo_stream_request? ⇒ Boolean
Check if request expects Turbo Stream response.
-
#turbo_stream_update_table(turbo_frame_id: "admin_table_content", partial: nil) ⇒ Object
Render Turbo Stream update for table.
Instance Method Details
#turbo_frame_id ⇒ String?
Get Turbo Frame ID from request
42 43 44 |
# File 'app/controllers/concerns/ruby_cms/admin_turbo_table.rb', line 42 def turbo_frame_id request.headers["Turbo-Frame"] end |
#turbo_frame_request? ⇒ Boolean
Check if this is a Turbo Frame request
9 10 11 |
# File 'app/controllers/concerns/ruby_cms/admin_turbo_table.rb', line 9 def turbo_frame_request? request.headers["Turbo-Frame"].present? end |
#turbo_redirect_to(url) ⇒ Object
Redirect with Turbo Frame support If Turbo Frame request, renders Turbo Stream redirect Otherwise performs normal redirect
30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/concerns/ruby_cms/admin_turbo_table.rb', line 30 def turbo_redirect_to(url, **) if turbo_frame_request? # For Turbo Frame requests, we can't redirect directly # Instead, we should render a Turbo Stream that updates the frame # or redirect the parent window else redirect_to(url, **) end end |
#turbo_render_index(turbo_frame_id: "admin_table_content") ⇒ Object
Render index action with Turbo Frame support If Turbo Frame request, renders only the table content Otherwise renders full page
17 18 19 20 21 22 23 |
# File 'app/controllers/concerns/ruby_cms/admin_turbo_table.rb', line 17 def turbo_render_index(turbo_frame_id: "admin_table_content") if turbo_frame_request? render partial: turbo_frame_id, layout: false else render :index end end |
#turbo_stream_replace_table(turbo_frame_id: "admin_table_content", partial: nil) ⇒ Object
Render Turbo Stream replace for table
63 64 65 66 |
# File 'app/controllers/concerns/ruby_cms/admin_turbo_table.rb', line 63 def turbo_stream_replace_table(turbo_frame_id: "admin_table_content", partial: nil) partial ||= turbo_frame_id render turbo_stream: turbo_stream.replace(turbo_frame_id, partial:) end |
#turbo_stream_request? ⇒ Boolean
Check if request expects Turbo Stream response
48 49 50 |
# File 'app/controllers/concerns/ruby_cms/admin_turbo_table.rb', line 48 def turbo_stream_request? request.headers["Accept"]&.include?("text/vnd.turbo-stream.html") end |
#turbo_stream_update_table(turbo_frame_id: "admin_table_content", partial: nil) ⇒ Object
Render Turbo Stream update for table
55 56 57 58 |
# File 'app/controllers/concerns/ruby_cms/admin_turbo_table.rb', line 55 def turbo_stream_update_table(turbo_frame_id: "admin_table_content", partial: nil) partial ||= turbo_frame_id render turbo_stream: turbo_stream.update(turbo_frame_id, partial:) end |