diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index bf030ee7..f38ccff3 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -126,7 +126,7 @@ class PostsController < ApplicationController @uuid = @post.uuid.value @name = params.require(:name) - render "posts/#{params.require(:attribute)}_value", layout: false + render render_path_from_attribute, layout: false else headers['HX-Retarget'] = "##{params.require(:form)}" headers['HX-Reswap'] = 'outerHTML' @@ -240,4 +240,13 @@ class PostsController < ApplicationController headers['HX-Trigger'] = triggers.to_json if triggers.present? end + + # @return [String] + def render_path_from_attribute + case params.require(:attribute) + when 'new_has_many' then 'posts/new_has_many_value' + when 'new_belongs_to' then 'posts/new_belongs_to_value' + else 'nothing' + end + end end