lundi 4 avril 2016

Redirect back after submit to last view with the selected Dropdowns

I have 2 views, at the first view "order/list" is one dropdown to select the provider and a textfield for date, this fields are used to sort the data. Behind each column is a button who redirect to an extra pop-up view "_edit_single_order" to edit the columns.

The Problem : if I press the submit-button at view _edit_single_order, it redirect me to my old view "list", but there my old Dropdown/Date selections are deleted. But i want my old selection. How can i fix that ? Should I pass (provider/date) variables in the redirection to _edit_single_order view and back?

Edit button in View list :

<div>
   <%= link_to t("order.show.edit_single_order"), edit_single_order_path(:id => orders_list.id), :disabled => !orders_list.invoices_id.nil?, :class => "btn btn-info btn-xs", :remote => true %>
</div>

View _edit_single_order :

<div class="modal fade" id="edit_single_order-<%= params[:id] %>">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title"><%= @cart_item.product.name %> bestellt von <%= @cart_item.user.fullname %></h4>
      </div>
      <div class="modal-body">
        <%= form_for(@cart_item, :url => url_for(:controller => 'orders', :action => 'edit_single_order_submit'), :html => { :class => "form-horizontal" }) do |f| %>
          <%= render "shared/error_messages", :target => @cart_item %>
          <%= render :partial => 'edit_single_order_form', :object => f %>
          <div class="modal-footer">
            <%= submit_tag(t('apply'), :class => "btn btn-primary") %>
            <a href="#" class="btn btn-warning" data-dismiss="modal"><%=  t('order.show.cancel_edit') %></a>
          </div>
        <%end%>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

Controller action submit_edit_single_order :

def edit_single_order_submit
   @cart_item = CartItem.find_by_id(params[:id])

   ( hide the update code...is not important for question) 

   redirect_back_or_default administrate_order_path
end

Aucun commentaire:

Enregistrer un commentaire