Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] The sort_link does not refer to the search criteria in the object passed in the first argument. #1469

Open
lobin-z0x50 opened this issue Dec 20, 2023 · 0 comments

Comments

@lobin-z0x50
Copy link

Suppose you write sort_link as follows.

<th><%= sort_link @search_form, :address_1 %></th>

At this time, sort_link is not looking at the search criteria in @search_form, but is looking at the params in the controller to create the query string for the link.
Therefore, even if the controller generates default search conditions, etc. and sets them in @search_form, the sort_link will not reflect them.

A workaround is to set the search condition to params[:q] as follows.

  def index
    @search_form = Facility.ransack(search_params)
    @search_form.sorts = ["ID asc"] if @search_form.sorts.empty?

    ...
  end

  private
    def search_params
      h = params.fetch(:q, default_search_params).permit(
          :groups_id_eq,
          :prefecture_id_eq,
          :address_1_start,
          :shelter_kind_eq,
          :facility_kind_eq,
          :s,
          :s => []
          )

      params[:q] = h
    end

Is this the intended design?
We would like to avoid changing params if possible.
Is there any other way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant