From 6164da2e38884f7ec424eafc6baccdf7fc564352 Mon Sep 17 00:00:00 2001 From: Jose Farias Date: Fri, 29 Nov 2024 17:05:32 -0600 Subject: [PATCH] Unnest uploads controller --- .../{action_text/markdown => }/uploads_controller.rb | 2 +- .../markdown => }/uploads/create.json.jbuilder | 0 config/routes.rb | 8 +++----- lib/rails_ext/action_text_tag_helper.rb | 2 +- lib/rails_ext/active_storage_sluggable.rb | 2 +- 5 files changed, 6 insertions(+), 8 deletions(-) rename app/controllers/{action_text/markdown => }/uploads_controller.rb (88%) rename app/views/{action_text/markdown => }/uploads/create.json.jbuilder (100%) diff --git a/app/controllers/action_text/markdown/uploads_controller.rb b/app/controllers/uploads_controller.rb similarity index 88% rename from app/controllers/action_text/markdown/uploads_controller.rb rename to app/controllers/uploads_controller.rb index 7444a6f7c..c7a97d81a 100644 --- a/app/controllers/action_text/markdown/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -1,4 +1,4 @@ -class ActionText::Markdown::UploadsController < ApplicationController +class UploadsController < ApplicationController include ActiveStorage::SetCurrent def create diff --git a/app/views/action_text/markdown/uploads/create.json.jbuilder b/app/views/uploads/create.json.jbuilder similarity index 100% rename from app/views/action_text/markdown/uploads/create.json.jbuilder rename to app/views/uploads/create.json.jbuilder diff --git a/config/routes.rb b/config/routes.rb index ab90b2124..39e1ab674 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -40,6 +40,9 @@ Rails.application.routes.draw do resource :first_run resource :session + resources :uploads, only: :create + get "/u/*slug" => "uploads#show", as: :upload + resources :users do scope module: :users do resource :avatar @@ -50,11 +53,6 @@ Rails.application.routes.draw do resources :stages, module: :workflows end - namespace :action_text, path: nil do - get "/u/*slug" => "markdown/uploads#show", as: :markdown_upload - post "/uploads" => "markdown/uploads#create", as: :markdown_uploads - end - get "join/:join_code", to: "users#new", as: :join post "join/:join_code", to: "users#create" get "up", to: "rails/health#show", as: :rails_health_check diff --git a/lib/rails_ext/action_text_tag_helper.rb b/lib/rails_ext/action_text_tag_helper.rb index 41dfb3ce7..d662da7b2 100644 --- a/lib/rails_ext/action_text_tag_helper.rb +++ b/lib/rails_ext/action_text_tag_helper.rb @@ -3,7 +3,7 @@ module ActionText def markdown_area(record, name, value: nil, data: {}, **options) field_name = "#{record.class.model_name.param_key}[#{name}]" value = record.safe_markdown_attribute(name).content.to_s if value.nil? - data = data.reverse_merge! uploads_url: action_text_markdown_uploads_url(format: "json") + data = data.reverse_merge! uploads_url: uploads_url(format: "json") tag.house_md value, name: field_name, data: data, **options end diff --git a/lib/rails_ext/active_storage_sluggable.rb b/lib/rails_ext/active_storage_sluggable.rb index d1a3b1e4f..d4d4be335 100644 --- a/lib/rails_ext/active_storage_sluggable.rb +++ b/lib/rails_ext/active_storage_sluggable.rb @@ -6,7 +6,7 @@ module ActiveStorage::Sluggable end def slug_url(host: ActiveStorage::Current.url_options[:host], port: ActiveStorage::Current.url_options[:port]) - Rails.application.routes.url_helpers.action_text_markdown_upload_url(slug, host: host, port: port) + Rails.application.routes.url_helpers.upload_url(slug, host: host, port: port) end private