Sha256: 686cdd2630ec713539b14a3379caaad9f1bea0d3758e79a161cdd13ba9d60b66
Contents?: true
Size: 1.38 KB
Versions: 13
Compression:
Stored size: 1.38 KB
Contents
--- sidebar_position: 3 title: Configuration --- Ransack may be easily configured. The best place to put configuration is in an initializer file at `config/initializers/ransack.rb`, containing code such as: ```ruby Ransack.configure do |config| # Change default search parameter key name. # Default key name is :q config.search_key = :query # Raise errors if a query contains an unknown predicate or attribute. # Default is true (do not raise error on unknown conditions). config.ignore_unknown_conditions = false # Globally display sort links without the order indicator arrow. # Default is false (sort order indicators are displayed). # This can also be configured individually in each sort link (see the README). config.hide_sort_order_indicators = true end ``` ## Custom search parameter key name Sometimes there are situations when the default search parameter name cannot be used, for instance, if there are two searches on one page. Another name may be set using the `search_key` option in the `ransack` or `search` methods in the controller, and in the `@search_form_for` method in the view. ### In the controller ```ruby @search = Log.ransack(params[:log_search], search_key: :log_search) # or @search = Log.search(params[:log_search], search_key: :log_search) ``` ### In the view ```erb <%= f.search_form_for @search, as: :log_search %> <%= sort_link(@search) %> ```
Version data entries
13 entries across 12 versions & 2 rubygems