lundi 13 mars 2017

Rails how update the object with another action name?

Rails how update the object with another action name?

i'm trying to update the attribute track_number of Order object with a another action name so track is where the user find the Order and track_done is where he update. but the attribute did not update!

someone know why this happen?

here is controllers

 def track
    @order = current_seller.orders.find(params[:id])
    if current_seller.blank?
      # redirect_to new_user_changes_path(current_user)

 redirect_to :back


      flash[:error] = 'error.'
    end
  end



def track_done
  order = Order.find(params[:id])
  flash = if order.update_attributes(params[:order])
              { success: 'saved.' }
            else
              { error: 'error.' }
            end
    if request.xhr?
      render json: flash
    else
      redirect_to track_order_path(order), flash: flash
    end
  end



the routes



  resources :orders, only: [:index, :update, :destroy] do

    member do

get :track
put :track_done

    end

end

the view

 <div class="block  margin_top">

    <div class="subcontent">

            <%= form_for @order, :url => track_done_order_path(@order), method: :put,  html: { class: 'form-inline' } do |f| %>


  <%=order.track_number %>

   <label>Code</label> <%= f.text_field   :track_number %> 

  <%= f.submit "Ad",  class: "btn_grey" %>


   <% end %>



  </div>
 </div>

Aucun commentaire:

Enregistrer un commentaire