Ransack: Ransack form search field value not persisted between requests when using alias

Created on 23 Jun 2016  路  6Comments  路  Source: activerecord-hackery/ransack

When I search, using an alias I cannot get the value of the searched parameter in the field.
In the name field I have tested and it's working fine.
My code:
In controller:

  def index
    @q = Customer.ransack(params[:q])
    @customers = @q.result(distinct: true)
  end

In model:

  ransack_alias :quick_search, :name_or_phone_or_mobile_or_email_or_vat_identification

In view:

      <%= search_form_for @q do |f| %>
      <%= f.search_field :quick_search_cont, class: "form-control"%>
    </div>
    <div id="table-filter" class="well filter-well">
      <div class="form-group">
        <%= f.label (:name) %>
        <%= f.search_field :name_cont, class: "form-control" %>
      </div>

Ransack version:
GIT
remote: git://github.com/activerecord-hackery/ransack.git
revision: 64d8c402e6e79e8ec2966a15c35b98196813ef8e

I'm using Ransack directly with:
Database: PostgreSQL
Rails: 5.0.0.rc1
ruby 2.2.5

Most helpful comment

If it helps anyone, I worked around this using value option:

= f.search_field :quick_search_cont, value: params.dig(:q, :quick_search_cont)

All 6 comments

same here

Ransack version:
GIT
remote: git://github.com/activerecord-hackery/ransack.git
revision: fd94685abc0d18d30a730a57fb3dbd8aff048f7d

Database: PostgreSQL
Rails: 5.0.0
ruby 2.3.1

Any update on this? I'm having the same problem.

If it helps anyone, I worked around this using value option:

= f.search_field :quick_search_cont, value: params.dig(:q, :quick_search_cont)

Same here.

Ransack: 1.8.3 / 1.8.2
Database: MySQL
Rails: 4.2.9
Ruby: 2.3.3

Same here

Ransack: 1.8.3
Database: PostgreSQL
Rails: 4.0.13
Ruby: 2.3.3

Same bug here

Ransack: 2.1.1
Database: MySQL
Rails: 5.2.2
Ruby: 2.5.3

Also ransack sorting ignores aliases.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MatsumotoHiroko picture MatsumotoHiroko  路  4Comments

seanfcarroll picture seanfcarroll  路  4Comments

senid231 picture senid231  路  4Comments

zenati picture zenati  路  4Comments

mbajur picture mbajur  路  5Comments