Problem is simple (solution is not): I would like to redirect to edit path after X model is created (I'll apply this to multiple models).
Are there any way to do it? I'm digging in source code, trying to find a reference to created instance, but can only find instance variables named after model (like @user
, which is harder to make generic).
So far, I found this answer which partially solves my problem: https://stackoverflow.com/a/22486025/312907
I'm still missing a reference to created model object.
In ActiveAdmin, just modify smart_resource_url, so that you don't have to mess with the create or update code:
controller do
def smart_resource_url
if create_another?
new_resource_url(create_another: params[:create_another])
else
edit_resource_url
end
end
end
If you want it to go back to the list view, put "collection_url" after the else.
If you want it to go back to the edit page, put "edit_resource_url" after the else.
Note that this redirect occurs BOTH after creating a new resource and after editing one.