{"record":{"id":"1b470a539ba3c9a3","repo":"activerecord-hackery/ransack","slug":"no-ransack-search-object-was-provided-to-method","errorCode":null,"errorMessage":"No Ransack::Search object was provided to #{method_name}!","messagePattern":"No Ransack::Search object was provided to #(.+?)!","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/ransack/helpers/form_helper.rb","lineNumber":103,"sourceCode":"      end\n\n      private\n\n        def extract_search_and_set_url(record, options, method_name)\n          if record.is_a? Ransack::Search\n            search = record\n            options[:url] ||= polymorphic_path(\n              search.klass, format: options.delete(:format)\n            )\n            search\n          elsif record.is_a?(Array) &&\n          (search = record.detect { |o| o.is_a?(Ransack::Search) })\n            options[:url] ||= polymorphic_path(\n              options_for(record), format: options.delete(:format)\n            )\n            search\n          else\n            raise ArgumentError,\n            \"No Ransack::Search object was provided to #{method_name}!\"\n          end\n        end\n\n        def build_turbo_options(options)\n          data_options = {}\n          if options[:turbo_frame]\n            data_options[:turbo_frame] = options.delete(:turbo_frame)\n          end\n          data_options[:turbo_action] = options.delete(:turbo_action) || 'advance'\n          { data: data_options }\n        end\n\n        def build_html_options(search, options, method)\n          {\n            class:  html_option_for(options[:class], search),\n            id:     html_option_for(options[:id], search),\n            method: method","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/activerecord-hackery/ransack/blob/e82f6bab3956c5597e7debbefa218d9e94e58ceb/lib/ransack/helpers/form_helper.rb#L85-L121","documentation":"search_form_for (and turbo_search_form_for) call extract_search_and_set_url, which accepts either a Ransack::Search or an array containing one (for polymorphic routing). If the record argument is neither — e.g. an ActiveRecord::Relation, a model instance, or nil — this ArgumentError naming the helper method is raised, because the helper cannot derive the form's URL class or fields without a search.","triggerScenarios":"search_form_for(@articles) where @articles = Article.all (a Relation); search_form_for(@article) (an instance); search_form_for([@article, Comment.new]) where the array contains no Ransack::Search; turbo_search_form_for(@people) with a relation.","commonSituations":"Converting an existing index view from form_for(@articles) to Ransack and only renaming the helper; forgetting the controller's @q assignment; nested-resource forms where the author forgot to include the search object in the array.","solutions":["Build the search in the controller: @q = Article.ransack(params[:q]) and use search_form_for(@q)","For nested/polymorphic forms, include the search in the array: search_form_for([@article, @q])","If a plain model form is truly wanted, use form_for/form_with instead of search_form_for"],"exampleFix":"# controller\n# before\ndef index\n  @articles = Article.all\nend\n\n# after\ndef index\n  @q = Article.ransack(params[:q])\n  @articles = @q.result.includes(:comments)\nend\n\n# view\n<%= search_form_for @q do |f| %> ... <% end %>","handlingStrategy":"type-guard","validationCode":"# controller: make the search unconditional before the view renders\ndef index\n  @q = Article.ransack(params[:q])\nend","typeGuard":"def search_or_array_with_search?(record)\n  record.is_a?(Ransack::Search) ||\n    (record.is_a?(Array) && record.any? { |o| o.is_a?(Ransack::Search) })\nend","tryCatchPattern":null,"preventionTips":["search_form_for's first argument is always the search object — never a relation or model instance","For nested resources use [@parent, @q] so polymorphic_path can route and the search is still present","Add a view spec for each search form to catch wrong record types at CI time"],"tags":["ruby","rails","ransack","search-form","views","argumenterror"],"backgroundTag":"form-builder-wrong-object","analyzedSha":"e82f6bab3956c5597e7debbefa218d9e94e58ceb","analyzedAt":"2026-08-21T19:30:23.639Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}