Skip to content

Commit 111a3d0

Browse files
committed
Better handle single table inheritance for resource redirects
Use #becomes method to ensure that the record is cast as the resource class before redirection so that the correct (parent) url helper is chosen
1 parent 7b3e34f commit 111a3d0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

app/controllers/better_together/resource_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def create
2626
authorize_resource
2727

2828
if @resource.save
29-
redirect_to @resource, notice: "#{resource_class.model_name.human} was successfully created."
29+
redirect_to @resource.becomes(resource_class), notice: "#{resource_class.model_name.human} was successfully created."
3030
else
3131
render :new, status: :unprocessable_entity
3232
end
@@ -36,7 +36,7 @@ def update
3636
authorize_resource
3737

3838
if @resource.update(resource_params)
39-
redirect_to @resource, notice: "#{resource_class.model_name.human} was successfully updated."
39+
redirect_to @resource.becomes(resource_class), notice: "#{resource_class.model_name.human} was successfully updated."
4040
else
4141
render :edit, status: :unprocessable_entity
4242
end

0 commit comments

Comments
 (0)