Rails paginated form not posting params occasionally

Multi tool use
up vote
1
down vote
favorite
I'm running into an intermittent problem with one of my forms.
I've tried to implement a batch destroy, and it works most of the time, but 1 time out of 10 it won't work, in the console I get an empty POST request with no paramaters.
Here is my view:
<h4>Suggestions </h4>
<%= submit_tag "Delete selected", form: "suggestions-delete-form", class: 'btn btn-danger' %>
<p class="card-text">
<% if @suggestions %>
<div class="table-responsive-sm">
<table class="table-sm", id="suggestion-table">
<tbody>
<%= form_tag collection_batch_destroy_path(@collection), method: :post, id: "suggestions-delete-form" do %>
<% @suggestions.each do |s| %>
<tr id='suggestion'>
<th style="width: 4%"><%= check_box_tag "item_ids", s.id, false, class: "form-check .selectable-checkbox" %></th>
<td><%if s.search.term.include?("-") %>
<%= Hpricot.uxs s.search.term.capitalize %>
<% else %>
<%= Hpricot.uxs s.search.term.titleize %>
<% end %>
</td>
<td style="width: 4%"><%= link_to fa_icon('plus-circle'), collection_item_choose_path(@collection, s),{ method: :post, class: "btn btn-primary btn-sm text-right" } %>
</td>
<td style="width: 4%" id='delete-suggestion'><%= link_to fa_icon('trash'), collection_item_destroy_path(@collection, s),{ method: :post, class: "btn btn-primary btn-sm text-right" } %><br>
</td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
</div>
<% end %>
</p>
These are my routes:
resources :sellers, only: [:show] do
resources :collections, shallow: true do
match 'item/choose', to: 'items#choose', via: 'post'
match 'item/remove', to: 'items#remove', via: 'post'
match 'item/destroy', to: 'items#destroy', via: 'post'
match 'batch_destroy', to: 'items#batch_destroy', via: 'post'
end
end
And here is my controller:
def batch_destroy
@collection = Collection.find(params[:collection_id])
if params[:item_ids] && params[:item_ids].size > 0
Item.where(id: params[:item_ids]).update_all(suggestion: false)
flash[:success] = "Suggestions successfully deleted"
else
flash[:danger] = "No items were selected"
end
redirect_to collection_path(@collection)
end
Here is an example of a batch destroy that worked:
Started POST "/collections/67/batch_destroy" for 127.0.0.1 at 2018-11-07 20:16:19 +0200
Processing by ItemsController#batch_destroy as HTML
Parameters: {"commit"=>"Delete selected", "utf8"=>"✓", "authenticity_token"=>"zEuCw1VX689LwCBcbNsC9JOd2cSVzcc1LxtkFN+xV3I2ORT6r/5aWM8iaNwo5U2LLFF/1lQDIAHQOoVylb4N3A==", "item_ids"=>["12729", "12730", "12731", "12732", "12733", "12735", "12736"], "collection_id"=>"67"}
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
Notification Load (0.5ms) SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = 1 ORDER BY "notifications"."id" DESC LIMIT $1 [["LIMIT", 3]]
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Seller Load (0.3ms) SELECT "sellers".* FROM "sellers" WHERE "sellers"."id" = $1 LIMIT $2 [["id", 6], ["LIMIT", 1]]
Shop Load (0.5ms) SELECT "shops".* FROM "shops" WHERE "shops"."id" = $1 LIMIT $2 [["id", 8], ["LIMIT", 1]]
Item Load (0.8ms) SELECT "items".* FROM "items" WHERE "items"."id" IN (12729, 12730, 12731, 12732, 12733, 12735, 12736)
(0.2ms) BEGIN
SQL (0.6ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.552499"], ["id", 12729]]
(1.1ms) COMMIT
(0.2ms) BEGIN
SQL (0.6ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.556805"], ["id", 12732]]
(2.2ms) COMMIT
(0.2ms) BEGIN
SQL (0.6ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.562274"], ["id", 12735]]
(3.2ms) COMMIT
(0.2ms) BEGIN
SQL (0.5ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.569024"], ["id", 12736]]
(1.3ms) COMMIT
(0.3ms) BEGIN
SQL (1.0ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.573374"], ["id", 12730]]
(5.1ms) COMMIT
(0.1ms) BEGIN
SQL (0.7ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.582742"], ["id", 12731]]
(1.0ms) COMMIT
(0.1ms) BEGIN
SQL (0.7ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.586827"], ["id", 12733]]
(2.9ms) COMMIT
Collection Load (0.3ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 67], ["LIMIT", 1]]
Redirected to http://localhost:3000/collections/67
Completed 302 Found in 57ms (ActiveRecord: 26.3ms)
And here I'm doing the same action (selecting some items, clicking "Delete selected", but it results in... nothing:
Started POST "/collections/67/batch_destroy" for 127.0.0.1 at 2018-11-08 09:36:02 +0200
Processing by ItemsController#batch_destroy as HTML
Parameters: {"commit"=>"Delete selected", "collection_id"=>"67"}
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
Notification Load (0.7ms) SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = 1 ORDER BY "notifications"."id" DESC LIMIT $1 [["LIMIT", 3]]
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Seller Load (0.5ms) SELECT "sellers".* FROM "sellers" WHERE "sellers"."id" = $1 LIMIT $2 [["id", 6], ["LIMIT", 1]]
Shop Load (0.3ms) SELECT "shops".* FROM "shops" WHERE "shops"."id" = $1 LIMIT $2 [["id", 8], ["LIMIT", 1]]
Item Load (0.5ms) SELECT "items".* FROM "items" WHERE "items"."id" IS NULL
Collection Load (0.2ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 67], ["LIMIT", 1]]
Redirected to http://localhost:3000/collections/67
Completed 302 Found in 13ms (ActiveRecord: 3.2ms)
As you can see, despite having checked some boxes, rails doesn't pass the corresponding IDs. I also get the flash message: "No items were selected".
This happens in both dev and production.
I would really appreciate any insight you might have. TIA!
EDIT:
Just removed will_paginate pagination on this form and now it works like a charm.
Anyone know what might be causing this?
ruby-on-rails forms post will-paginate
add a comment |
up vote
1
down vote
favorite
I'm running into an intermittent problem with one of my forms.
I've tried to implement a batch destroy, and it works most of the time, but 1 time out of 10 it won't work, in the console I get an empty POST request with no paramaters.
Here is my view:
<h4>Suggestions </h4>
<%= submit_tag "Delete selected", form: "suggestions-delete-form", class: 'btn btn-danger' %>
<p class="card-text">
<% if @suggestions %>
<div class="table-responsive-sm">
<table class="table-sm", id="suggestion-table">
<tbody>
<%= form_tag collection_batch_destroy_path(@collection), method: :post, id: "suggestions-delete-form" do %>
<% @suggestions.each do |s| %>
<tr id='suggestion'>
<th style="width: 4%"><%= check_box_tag "item_ids", s.id, false, class: "form-check .selectable-checkbox" %></th>
<td><%if s.search.term.include?("-") %>
<%= Hpricot.uxs s.search.term.capitalize %>
<% else %>
<%= Hpricot.uxs s.search.term.titleize %>
<% end %>
</td>
<td style="width: 4%"><%= link_to fa_icon('plus-circle'), collection_item_choose_path(@collection, s),{ method: :post, class: "btn btn-primary btn-sm text-right" } %>
</td>
<td style="width: 4%" id='delete-suggestion'><%= link_to fa_icon('trash'), collection_item_destroy_path(@collection, s),{ method: :post, class: "btn btn-primary btn-sm text-right" } %><br>
</td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
</div>
<% end %>
</p>
These are my routes:
resources :sellers, only: [:show] do
resources :collections, shallow: true do
match 'item/choose', to: 'items#choose', via: 'post'
match 'item/remove', to: 'items#remove', via: 'post'
match 'item/destroy', to: 'items#destroy', via: 'post'
match 'batch_destroy', to: 'items#batch_destroy', via: 'post'
end
end
And here is my controller:
def batch_destroy
@collection = Collection.find(params[:collection_id])
if params[:item_ids] && params[:item_ids].size > 0
Item.where(id: params[:item_ids]).update_all(suggestion: false)
flash[:success] = "Suggestions successfully deleted"
else
flash[:danger] = "No items were selected"
end
redirect_to collection_path(@collection)
end
Here is an example of a batch destroy that worked:
Started POST "/collections/67/batch_destroy" for 127.0.0.1 at 2018-11-07 20:16:19 +0200
Processing by ItemsController#batch_destroy as HTML
Parameters: {"commit"=>"Delete selected", "utf8"=>"✓", "authenticity_token"=>"zEuCw1VX689LwCBcbNsC9JOd2cSVzcc1LxtkFN+xV3I2ORT6r/5aWM8iaNwo5U2LLFF/1lQDIAHQOoVylb4N3A==", "item_ids"=>["12729", "12730", "12731", "12732", "12733", "12735", "12736"], "collection_id"=>"67"}
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
Notification Load (0.5ms) SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = 1 ORDER BY "notifications"."id" DESC LIMIT $1 [["LIMIT", 3]]
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Seller Load (0.3ms) SELECT "sellers".* FROM "sellers" WHERE "sellers"."id" = $1 LIMIT $2 [["id", 6], ["LIMIT", 1]]
Shop Load (0.5ms) SELECT "shops".* FROM "shops" WHERE "shops"."id" = $1 LIMIT $2 [["id", 8], ["LIMIT", 1]]
Item Load (0.8ms) SELECT "items".* FROM "items" WHERE "items"."id" IN (12729, 12730, 12731, 12732, 12733, 12735, 12736)
(0.2ms) BEGIN
SQL (0.6ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.552499"], ["id", 12729]]
(1.1ms) COMMIT
(0.2ms) BEGIN
SQL (0.6ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.556805"], ["id", 12732]]
(2.2ms) COMMIT
(0.2ms) BEGIN
SQL (0.6ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.562274"], ["id", 12735]]
(3.2ms) COMMIT
(0.2ms) BEGIN
SQL (0.5ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.569024"], ["id", 12736]]
(1.3ms) COMMIT
(0.3ms) BEGIN
SQL (1.0ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.573374"], ["id", 12730]]
(5.1ms) COMMIT
(0.1ms) BEGIN
SQL (0.7ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.582742"], ["id", 12731]]
(1.0ms) COMMIT
(0.1ms) BEGIN
SQL (0.7ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.586827"], ["id", 12733]]
(2.9ms) COMMIT
Collection Load (0.3ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 67], ["LIMIT", 1]]
Redirected to http://localhost:3000/collections/67
Completed 302 Found in 57ms (ActiveRecord: 26.3ms)
And here I'm doing the same action (selecting some items, clicking "Delete selected", but it results in... nothing:
Started POST "/collections/67/batch_destroy" for 127.0.0.1 at 2018-11-08 09:36:02 +0200
Processing by ItemsController#batch_destroy as HTML
Parameters: {"commit"=>"Delete selected", "collection_id"=>"67"}
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
Notification Load (0.7ms) SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = 1 ORDER BY "notifications"."id" DESC LIMIT $1 [["LIMIT", 3]]
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Seller Load (0.5ms) SELECT "sellers".* FROM "sellers" WHERE "sellers"."id" = $1 LIMIT $2 [["id", 6], ["LIMIT", 1]]
Shop Load (0.3ms) SELECT "shops".* FROM "shops" WHERE "shops"."id" = $1 LIMIT $2 [["id", 8], ["LIMIT", 1]]
Item Load (0.5ms) SELECT "items".* FROM "items" WHERE "items"."id" IS NULL
Collection Load (0.2ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 67], ["LIMIT", 1]]
Redirected to http://localhost:3000/collections/67
Completed 302 Found in 13ms (ActiveRecord: 3.2ms)
As you can see, despite having checked some boxes, rails doesn't pass the corresponding IDs. I also get the flash message: "No items were selected".
This happens in both dev and production.
I would really appreciate any insight you might have. TIA!
EDIT:
Just removed will_paginate pagination on this form and now it works like a charm.
Anyone know what might be causing this?
ruby-on-rails forms post will-paginate
Long shot but does this happen after you haven't clicked on the page in a while? I've noticed that your unsuccessful attempt does not contain the authenticity token.
– ThorTL67
18 hours ago
@ThorTL67 no, the selection and the action are immediate. Thanks for trying though :)
– Maayan Naveh
18 hours ago
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm running into an intermittent problem with one of my forms.
I've tried to implement a batch destroy, and it works most of the time, but 1 time out of 10 it won't work, in the console I get an empty POST request with no paramaters.
Here is my view:
<h4>Suggestions </h4>
<%= submit_tag "Delete selected", form: "suggestions-delete-form", class: 'btn btn-danger' %>
<p class="card-text">
<% if @suggestions %>
<div class="table-responsive-sm">
<table class="table-sm", id="suggestion-table">
<tbody>
<%= form_tag collection_batch_destroy_path(@collection), method: :post, id: "suggestions-delete-form" do %>
<% @suggestions.each do |s| %>
<tr id='suggestion'>
<th style="width: 4%"><%= check_box_tag "item_ids", s.id, false, class: "form-check .selectable-checkbox" %></th>
<td><%if s.search.term.include?("-") %>
<%= Hpricot.uxs s.search.term.capitalize %>
<% else %>
<%= Hpricot.uxs s.search.term.titleize %>
<% end %>
</td>
<td style="width: 4%"><%= link_to fa_icon('plus-circle'), collection_item_choose_path(@collection, s),{ method: :post, class: "btn btn-primary btn-sm text-right" } %>
</td>
<td style="width: 4%" id='delete-suggestion'><%= link_to fa_icon('trash'), collection_item_destroy_path(@collection, s),{ method: :post, class: "btn btn-primary btn-sm text-right" } %><br>
</td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
</div>
<% end %>
</p>
These are my routes:
resources :sellers, only: [:show] do
resources :collections, shallow: true do
match 'item/choose', to: 'items#choose', via: 'post'
match 'item/remove', to: 'items#remove', via: 'post'
match 'item/destroy', to: 'items#destroy', via: 'post'
match 'batch_destroy', to: 'items#batch_destroy', via: 'post'
end
end
And here is my controller:
def batch_destroy
@collection = Collection.find(params[:collection_id])
if params[:item_ids] && params[:item_ids].size > 0
Item.where(id: params[:item_ids]).update_all(suggestion: false)
flash[:success] = "Suggestions successfully deleted"
else
flash[:danger] = "No items were selected"
end
redirect_to collection_path(@collection)
end
Here is an example of a batch destroy that worked:
Started POST "/collections/67/batch_destroy" for 127.0.0.1 at 2018-11-07 20:16:19 +0200
Processing by ItemsController#batch_destroy as HTML
Parameters: {"commit"=>"Delete selected", "utf8"=>"✓", "authenticity_token"=>"zEuCw1VX689LwCBcbNsC9JOd2cSVzcc1LxtkFN+xV3I2ORT6r/5aWM8iaNwo5U2LLFF/1lQDIAHQOoVylb4N3A==", "item_ids"=>["12729", "12730", "12731", "12732", "12733", "12735", "12736"], "collection_id"=>"67"}
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
Notification Load (0.5ms) SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = 1 ORDER BY "notifications"."id" DESC LIMIT $1 [["LIMIT", 3]]
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Seller Load (0.3ms) SELECT "sellers".* FROM "sellers" WHERE "sellers"."id" = $1 LIMIT $2 [["id", 6], ["LIMIT", 1]]
Shop Load (0.5ms) SELECT "shops".* FROM "shops" WHERE "shops"."id" = $1 LIMIT $2 [["id", 8], ["LIMIT", 1]]
Item Load (0.8ms) SELECT "items".* FROM "items" WHERE "items"."id" IN (12729, 12730, 12731, 12732, 12733, 12735, 12736)
(0.2ms) BEGIN
SQL (0.6ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.552499"], ["id", 12729]]
(1.1ms) COMMIT
(0.2ms) BEGIN
SQL (0.6ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.556805"], ["id", 12732]]
(2.2ms) COMMIT
(0.2ms) BEGIN
SQL (0.6ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.562274"], ["id", 12735]]
(3.2ms) COMMIT
(0.2ms) BEGIN
SQL (0.5ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.569024"], ["id", 12736]]
(1.3ms) COMMIT
(0.3ms) BEGIN
SQL (1.0ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.573374"], ["id", 12730]]
(5.1ms) COMMIT
(0.1ms) BEGIN
SQL (0.7ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.582742"], ["id", 12731]]
(1.0ms) COMMIT
(0.1ms) BEGIN
SQL (0.7ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.586827"], ["id", 12733]]
(2.9ms) COMMIT
Collection Load (0.3ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 67], ["LIMIT", 1]]
Redirected to http://localhost:3000/collections/67
Completed 302 Found in 57ms (ActiveRecord: 26.3ms)
And here I'm doing the same action (selecting some items, clicking "Delete selected", but it results in... nothing:
Started POST "/collections/67/batch_destroy" for 127.0.0.1 at 2018-11-08 09:36:02 +0200
Processing by ItemsController#batch_destroy as HTML
Parameters: {"commit"=>"Delete selected", "collection_id"=>"67"}
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
Notification Load (0.7ms) SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = 1 ORDER BY "notifications"."id" DESC LIMIT $1 [["LIMIT", 3]]
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Seller Load (0.5ms) SELECT "sellers".* FROM "sellers" WHERE "sellers"."id" = $1 LIMIT $2 [["id", 6], ["LIMIT", 1]]
Shop Load (0.3ms) SELECT "shops".* FROM "shops" WHERE "shops"."id" = $1 LIMIT $2 [["id", 8], ["LIMIT", 1]]
Item Load (0.5ms) SELECT "items".* FROM "items" WHERE "items"."id" IS NULL
Collection Load (0.2ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 67], ["LIMIT", 1]]
Redirected to http://localhost:3000/collections/67
Completed 302 Found in 13ms (ActiveRecord: 3.2ms)
As you can see, despite having checked some boxes, rails doesn't pass the corresponding IDs. I also get the flash message: "No items were selected".
This happens in both dev and production.
I would really appreciate any insight you might have. TIA!
EDIT:
Just removed will_paginate pagination on this form and now it works like a charm.
Anyone know what might be causing this?
ruby-on-rails forms post will-paginate
I'm running into an intermittent problem with one of my forms.
I've tried to implement a batch destroy, and it works most of the time, but 1 time out of 10 it won't work, in the console I get an empty POST request with no paramaters.
Here is my view:
<h4>Suggestions </h4>
<%= submit_tag "Delete selected", form: "suggestions-delete-form", class: 'btn btn-danger' %>
<p class="card-text">
<% if @suggestions %>
<div class="table-responsive-sm">
<table class="table-sm", id="suggestion-table">
<tbody>
<%= form_tag collection_batch_destroy_path(@collection), method: :post, id: "suggestions-delete-form" do %>
<% @suggestions.each do |s| %>
<tr id='suggestion'>
<th style="width: 4%"><%= check_box_tag "item_ids", s.id, false, class: "form-check .selectable-checkbox" %></th>
<td><%if s.search.term.include?("-") %>
<%= Hpricot.uxs s.search.term.capitalize %>
<% else %>
<%= Hpricot.uxs s.search.term.titleize %>
<% end %>
</td>
<td style="width: 4%"><%= link_to fa_icon('plus-circle'), collection_item_choose_path(@collection, s),{ method: :post, class: "btn btn-primary btn-sm text-right" } %>
</td>
<td style="width: 4%" id='delete-suggestion'><%= link_to fa_icon('trash'), collection_item_destroy_path(@collection, s),{ method: :post, class: "btn btn-primary btn-sm text-right" } %><br>
</td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
</div>
<% end %>
</p>
These are my routes:
resources :sellers, only: [:show] do
resources :collections, shallow: true do
match 'item/choose', to: 'items#choose', via: 'post'
match 'item/remove', to: 'items#remove', via: 'post'
match 'item/destroy', to: 'items#destroy', via: 'post'
match 'batch_destroy', to: 'items#batch_destroy', via: 'post'
end
end
And here is my controller:
def batch_destroy
@collection = Collection.find(params[:collection_id])
if params[:item_ids] && params[:item_ids].size > 0
Item.where(id: params[:item_ids]).update_all(suggestion: false)
flash[:success] = "Suggestions successfully deleted"
else
flash[:danger] = "No items were selected"
end
redirect_to collection_path(@collection)
end
Here is an example of a batch destroy that worked:
Started POST "/collections/67/batch_destroy" for 127.0.0.1 at 2018-11-07 20:16:19 +0200
Processing by ItemsController#batch_destroy as HTML
Parameters: {"commit"=>"Delete selected", "utf8"=>"✓", "authenticity_token"=>"zEuCw1VX689LwCBcbNsC9JOd2cSVzcc1LxtkFN+xV3I2ORT6r/5aWM8iaNwo5U2LLFF/1lQDIAHQOoVylb4N3A==", "item_ids"=>["12729", "12730", "12731", "12732", "12733", "12735", "12736"], "collection_id"=>"67"}
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
Notification Load (0.5ms) SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = 1 ORDER BY "notifications"."id" DESC LIMIT $1 [["LIMIT", 3]]
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Seller Load (0.3ms) SELECT "sellers".* FROM "sellers" WHERE "sellers"."id" = $1 LIMIT $2 [["id", 6], ["LIMIT", 1]]
Shop Load (0.5ms) SELECT "shops".* FROM "shops" WHERE "shops"."id" = $1 LIMIT $2 [["id", 8], ["LIMIT", 1]]
Item Load (0.8ms) SELECT "items".* FROM "items" WHERE "items"."id" IN (12729, 12730, 12731, 12732, 12733, 12735, 12736)
(0.2ms) BEGIN
SQL (0.6ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.552499"], ["id", 12729]]
(1.1ms) COMMIT
(0.2ms) BEGIN
SQL (0.6ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.556805"], ["id", 12732]]
(2.2ms) COMMIT
(0.2ms) BEGIN
SQL (0.6ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.562274"], ["id", 12735]]
(3.2ms) COMMIT
(0.2ms) BEGIN
SQL (0.5ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.569024"], ["id", 12736]]
(1.3ms) COMMIT
(0.3ms) BEGIN
SQL (1.0ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.573374"], ["id", 12730]]
(5.1ms) COMMIT
(0.1ms) BEGIN
SQL (0.7ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.582742"], ["id", 12731]]
(1.0ms) COMMIT
(0.1ms) BEGIN
SQL (0.7ms) UPDATE "items" SET "suggestion" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["suggestion", "f"], ["updated_at", "2018-11-07 18:16:19.586827"], ["id", 12733]]
(2.9ms) COMMIT
Collection Load (0.3ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 67], ["LIMIT", 1]]
Redirected to http://localhost:3000/collections/67
Completed 302 Found in 57ms (ActiveRecord: 26.3ms)
And here I'm doing the same action (selecting some items, clicking "Delete selected", but it results in... nothing:
Started POST "/collections/67/batch_destroy" for 127.0.0.1 at 2018-11-08 09:36:02 +0200
Processing by ItemsController#batch_destroy as HTML
Parameters: {"commit"=>"Delete selected", "collection_id"=>"67"}
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
Notification Load (0.7ms) SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = 1 ORDER BY "notifications"."id" DESC LIMIT $1 [["LIMIT", 3]]
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Seller Load (0.5ms) SELECT "sellers".* FROM "sellers" WHERE "sellers"."id" = $1 LIMIT $2 [["id", 6], ["LIMIT", 1]]
Shop Load (0.3ms) SELECT "shops".* FROM "shops" WHERE "shops"."id" = $1 LIMIT $2 [["id", 8], ["LIMIT", 1]]
Item Load (0.5ms) SELECT "items".* FROM "items" WHERE "items"."id" IS NULL
Collection Load (0.2ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 67], ["LIMIT", 1]]
Redirected to http://localhost:3000/collections/67
Completed 302 Found in 13ms (ActiveRecord: 3.2ms)
As you can see, despite having checked some boxes, rails doesn't pass the corresponding IDs. I also get the flash message: "No items were selected".
This happens in both dev and production.
I would really appreciate any insight you might have. TIA!
EDIT:
Just removed will_paginate pagination on this form and now it works like a charm.
Anyone know what might be causing this?
ruby-on-rails forms post will-paginate
ruby-on-rails forms post will-paginate
edited 15 hours ago
asked 21 hours ago
Maayan Naveh
868
868
Long shot but does this happen after you haven't clicked on the page in a while? I've noticed that your unsuccessful attempt does not contain the authenticity token.
– ThorTL67
18 hours ago
@ThorTL67 no, the selection and the action are immediate. Thanks for trying though :)
– Maayan Naveh
18 hours ago
add a comment |
Long shot but does this happen after you haven't clicked on the page in a while? I've noticed that your unsuccessful attempt does not contain the authenticity token.
– ThorTL67
18 hours ago
@ThorTL67 no, the selection and the action are immediate. Thanks for trying though :)
– Maayan Naveh
18 hours ago
Long shot but does this happen after you haven't clicked on the page in a while? I've noticed that your unsuccessful attempt does not contain the authenticity token.
– ThorTL67
18 hours ago
Long shot but does this happen after you haven't clicked on the page in a while? I've noticed that your unsuccessful attempt does not contain the authenticity token.
– ThorTL67
18 hours ago
@ThorTL67 no, the selection and the action are immediate. Thanks for trying though :)
– Maayan Naveh
18 hours ago
@ThorTL67 no, the selection and the action are immediate. Thanks for trying though :)
– Maayan Naveh
18 hours ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53202915%2frails-paginated-form-not-posting-params-occasionally%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
cpb1FxQZbm3 OSnkcVMv,qM9kx,58MYZDRb 3 JY sgBg68vsF1VbziO orYfDWORWc,8zxQfas
Long shot but does this happen after you haven't clicked on the page in a while? I've noticed that your unsuccessful attempt does not contain the authenticity token.
– ThorTL67
18 hours ago
@ThorTL67 no, the selection and the action are immediate. Thanks for trying though :)
– Maayan Naveh
18 hours ago