Rails: How to pass a parameter in PATCH action?

Viewed 112

I am trying to pass the parameter @step_user_offer as a parameter in the button in the patch action:

<% @offer.number_of_steps.times do |step_number| %>
 <h2> Step Number <%= step_number + 1 %> </h2>
 <% search_for_user_offers_in_step(step_number + 1).each do |step_user_offer| %>
   <%= @step_user_offer = step_user_offer %>
   <%= step_user_offer.user.name %>


   <%= button_to "Approve Step", approved_step_path(@step_user_offer), method: :patch %>
   <%= button_to "Step not approved", not_approved_step_path(@step_user_offer), method: :patch %>
 <% end %>

<% end %>

In my routes:

  patch '/offers/:id/approved_step', to: "offers#approved_step", as: "approved_step"
  patch '/offers/:id/not_approved_step', to: "offers#not_approved_step", as: "not_approved_step"

In the Offers_controller:

  def approved_step
    print @step_user_offer
    debugger
    redirect_to offer_path(params[:id])
  end

  def not_approved_step
    redirect_to offer_path(params[:id])
  end

When I try to access the variable using the debugger in the controller, it says the variable is nil. However, I know the variable is not nil (in the html, I can see the step_user_offer.user.name). I want to know how to pass variables in the update method. I would appreciate any help.

0 Answers
Related