According to Ransack
documentation, there is a possibility to pass custom arguments to a ransacker method:
class Person < ApplicationRecord
ransacker :author_max_title_of_article_where_body_length_between, args: [:parent, :ransacker_args] do |parent, args|
min, max = args
query = <<-SQL
(SELECT MAX(articles.title)
FROM articles
WHERE articles.person_id = people.id
AND CHAR_LENGTH(articles.body) BETWEEN #{min.to_i} AND #{max.to_i}
GROUP BY articles.person_id
)
SQL
Arel.sql(query)
end
end
In the same documentation there is even an example of passing custom arguments:
Person.ransack(
conditions: [{
attributes: {
'0' => {
name: 'author_max_title_of_article_where_body_length_between',
ransacker_args: [10, 100]
}
},
predicate_name: 'cont',
values: ['Ransackers can take arguments']
}]
)
However, there is no documentation on how can I pass that custom arguments from a view, as there appears to be no search_form_for
helpers to do that.
Is there a way of passing these arguments through the form, without needing to parse the parameters in the controller to perform the search as pointed in the example?