Rails ActiveAdmin - change the after update redirect_to

前端 未结 6 1163
青春惊慌失措
青春惊慌失措 2020-12-31 04:01

I have a Feature page that belongs to the Car page. That is working exactly how I want to, except for one thing.

After creating, updating or destroying, I want the

6条回答
  •  时光说笑
    2020-12-31 04:15

    Here is a solution that also works with create_another, using parent and child for model names.

    This solution assumes that you show children as part of parent (e.g. via table_for) so you do not need child's index method.

    In resource override controller's smart_resource_url and index methods:

      controller do
        def smart_resource_url
          if create_another?
            new_resource_url(create_another: params[:create_another])
          else
            parent_path(params[:parent_id])
          end
        end
    
        def index
          redirect_to parent_path(params[:parent_id])
        end
      end
    

提交回复
热议问题