Associations with underscores? #178

TrevorS opened this Issue Dec 19, 2012 · 1 comment


None yet

3 participants

TrevorS commented Dec 19, 2012

I'm having a problem creating a form to search a model with an association.

Summary Model:

class CiberBatchSummary < ActiveRecord::Base
  has_many :ciber_air_and_toll_records
  # has attribute creation_date:date

Record Model:

class CiberAirAndTollRecord < ActiveRecord::Base
  belongs_to :ciber_batch_summary
  # has attribute call_date:date


class CiberBatchSummariesController < ApplicationController
  def index
    @search =[:q])
    @ciber_batch_summaries = @search.result.paginate(page: params[:page])

Search Form:

= search_form_for @search do |f|

  -# all of the fields from CiberBatchSummary work
  = f.label :creation_date_gteq, 'Creation Date Start'
  = f.text_field :creation_date_gteq

  -# none of the fields from CiberAirAndTollRecord work
  = f.label :ciber_air_and_toll_records_call_date_gteq, 'Call Date Start'
  = f.text_field :ciber_air_and_toll_records_call_date_gteq

  = f.submit 'Search'

The error message:

undefined method `ciber_air_and_toll_records_call_date_gteq' for #<Ransack::Search:0x0000000826ae78>`

Does Ransack not like associated models with underscores in their names, or am I just doing something totally wrong?


avit commented Nov 14, 2013

This is a duplicate of #299. Your association name has _and_, which Ransack splits to build queries.

@jonatack jonatack closed this Dec 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment