mardi 5 avril 2016

Rails - Redirection from 2 views to 1 edit_view and back with get-params

I have 2 views, there is on both a edit button. This button redirect to the edit_view. If I submit there the redirect shoul bring me back to the views where i came from. And pass id params back with get in the URL to one of this views.

Model:

localhost:3000/order/list > /order/edit_single_order > localhost:3000/order/list?id=1

localhost:3000/order/administrate > /order/edit_single_order > /order/administrate

The redirection :

    def redirect_to_back_or_default_params(default = root_url, *args)
      if request.env['HTTP_REFERER'].present? && request.env['HTTP_REFERER'] != request.env['REQUEST_URI']
        redirect_to :back, *args
      else
        redirect_to default, *args
      end
    end

The Controller-redirect :

redirect_to_back_or_default_params administrate_order_path(:provider_id => @cart_item.product.provider.id)

Aucun commentaire:

Enregistrer un commentaire