ransack
ransack copied to clipboard
search_field don't preserve values between requests for alias
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?
I'm seeing this also
@fidalgo @supairish Do you see this on 2.1.1 too?
@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
I see this too with 2.1.1
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"
This is still an issue on latest master