Skip to content

Create ransack helper to auto-create the query arguments from ransackable_attributes and maybe ransackable_associations #1882

Open
@adrianthedev

Description

@adrianthedev

Feature

Instead of duplicating the code and having a big query method, create a helper that will output all the attributes from ransackable_attributes. Maybe add an option for associations.

# instead of 
query.ransack(company_name_cont: params[:q], user_first_name_cont: params[:q], user_last_name_cont: params[:q], user_phone_cont: params[:q], user_username_cont: params[:q], requester_first_name_cont: params[:q], requester_last_name_cont: params[:q], requester_phone_cont: params[:q], requester_username_cont: params[:q], m: "or").result(distinct: false)

# have this
query.ransack(compile_ransack_attributes_for(User)).result(distinct: true)

From here

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Triage

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions