Reputation: 233
So I have this code in my views to create a button that approves all 5 star reviews. The issue I'm facing is that button_to
doesn't hide the params and order_ids is about 200 order objects. So when I click on the button, I get the error
Request-URI Too Large WEBrick::HTTPStatus::RequestURITooLarge
I think I need to use the form_tag
helper but I'm not too sure how to make a button with form_tag
. Or how to link the two things.
<div style="margin: 0 0 50px 0">
<%= button_to "Approve reviews with 5 stars",
{ action: :approve_reviews, order_ids: @orders, rating: 5 }
, method: :post %>
</div>
Upvotes: 0
Views: 349
Reputation: 8710
You can simply add params:{}
in the end to your button_to
<%= button_to "Approve reviews with 5 stars", action: :approve_reviews, params: {order_ids: @orders, rating: 5} %>
Note: by default the method will be post so you don't have to specify the method.
Hope it helps!
Upvotes: 1
Reputation: 3213
I'd recommend doing it this way -
form
and a hidden field that contains the values for the order IDs (and probably Rating, unless you have your routes configured for it)Have a simple button that just submits the form when clicked
<%= form_tag({ :action => :approve_reviews }) do -%>
<%= hidden_field_tag :order_ids, :value => @orders %>
<%= hidden_field_tag :rating, :value => 5 %>
<%= submit_tag "Approve reviews with 5 stars" %>
<% end -%>
Upvotes: 0
Reputation: 2113
Try something like this:
<%= form_tag({ action: :approve_reviews, rating: 5 }) do -%>
<%= hidden_field_tag 'order_ids', @orders %>
<%= submit_tag 'Approve reviews with 5 stars' %>
<%= end -%>
Upvotes: 0