Skip to content

Commit 71ceb6f

Browse files
Add view path for task details partials
When trying to render task details partials in the `demo` app, I ran into a problem with the strictly defined partial route in Flex. Flex had defined `task/details/{partial name}` as the route to find the partial...which meant that the parent app would always need to have their tasks route be in a `task` directory. Adding this view directory for only the `show` route allows the parent app to name their tasks directory whatever they want.
1 parent 70daabd commit 71ceb6f

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

app/controllers/flex/tasks_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class TasksController < ::ApplicationController
55
helper DateHelper
66

77
before_action :set_task, only: %i[ show update ]
8+
before_action :add_task_details_view_path, only: %i[ show ]
89

910
def task_class
1011
controller_path.classify.constantize
@@ -33,6 +34,10 @@ def set_task
3334
@task = task_class.find(params[:id]) if params[:id].present?
3435
end
3536

37+
def add_task_details_view_path
38+
prepend_view_path "app/views/#{controller_path}"
39+
end
40+
3641
def index_filter_params
3742
params.permit(:filter_date, :filter_type, :filter_status)
3843
end

app/views/flex/tasks/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<% if content_for?(:task_details_partial) %>
5858
<%= yield(:task_details_partial) %>
5959
<% else %>
60-
<%= render partial: "tasks/details/#{task.type.underscore}", locals: local_assigns.to_h %>
60+
<%= render partial: "details/#{task.type.underscore}", locals: local_assigns.to_h %>
6161
<% end %>
6262
</section>
6363
</main>

0 commit comments

Comments
 (0)