ransack icon indicating copy to clipboard operation
ransack copied to clipboard

search_field don't preserve values between requests for alias

Open fidalgo opened this issue 6 years ago • 6 comments

Hi! First of all thanks for your work :tada:

I'm using the ransack (1.8.8) with a Rails 5.1 and Ruby 2.4.3 with the following code:

Ransack alias: ransack_alias :quick_search, :sequence_or_order_customer_name_or_order_customer_vat_identification_or_order_line_items_description

and this form:

        <%= f.search_field :quick_search_cont, value: params.dig(:q, :quick_search_cont), class: "form-control"%>
        <span class="input-group-btn">
          <%= button_tag type: :search, class: 'btn btn-primary' do %>
            <%= t('actions.search') %>
            <span class="fas fa-search"></span>
          <% end %>
        </span>
......
    <% end %>

and I need to add value: params.dig(:q, :FIELD_NAME) to every search_field in my form, to have the values binded in the form, ie, when the results are returned and the page rendered I have the search input value filled.

Where is an url example: http://localhost:3000/invoices?utf8=%E2%9C%93&q%5Bquick_search_cont%5D=&button=&q%5Binvoice_search_cont%5D=&q%5Bperson_cont%5D=dias&q%5Bproduct_search_cont%5D=

Am I doing something wrong or there is a bug in the gem?

fidalgo avatar May 03 '18 16:05 fidalgo

I'm seeing this also

supairish avatar Dec 06 '18 17:12 supairish

@fidalgo @supairish Do you see this on 2.1.1 too?

gregmolnar avatar Dec 07 '18 08:12 gregmolnar

@gregmolnar I'm not sure, i'm linking to master in our Gemfile. I'll see if i have time today to try 2.1.1

supairish avatar Dec 07 '18 16:12 supairish

I see this too with 2.1.1

jean-francois-labbe avatar Dec 14 '18 13:12 jean-francois-labbe

2.3.0 also has the same bug:

class SomeModel < ActiveRecord::Base
  ransack_alias :abc, :name_or_address_or_something_else
end

r = SomeModel.ransack({abc_cont: "xyz"})
r.abc_cont
# => nil
r.name_or_address_or_something_else_cont
# => "xyz"

teoulas avatar Jan 24 '20 13:01 teoulas

This is still an issue on latest master

mike-northsail avatar Feb 06 '21 00:02 mike-northsail