I have dispute object that belongs to order and i would like to create it on orders view so: How can create a object on another object page?
the route is:
dispute_sent_order_path(@order), :html => {:method => :post} do |f| %>
resources :orders, only: [:index, :update, :destroy] do
member do
get :dispute
post :dispute_sent
put :dispute_done
end
end
def dispute
@order = current_user.orders.find(params[:id])
if current_user.address.blank?
redirect_to edit_user_path
flash[:error] = 'error'
else
@dispute = Dispute.new
end
end
def dispute_sent
@order = current_user.orders.find(params[:id])
if current_user == @order.buyer
dispute = @order.dispute.nil? ? Dispute.new : @order.dispute
params[:status] == 'Open'
if dispute.save
flash[:success] = 'hooray'
end
else
flash[:error] = 'Error'
end
redirect_to :back
end
end
Aucun commentaire:
Enregistrer un commentaire