Associations with underscores? #178

Closed
TrevorS opened this Issue Dec 19, 2012 · 1 comment

Projects

None yet

3 participants

@TrevorS
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
end

Record Model:

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

Controller:

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

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?

Thanks!

@avit
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