Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Associations with underscores? #178

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

Associations with underscores? #178

TrevorS opened this issue Dec 19, 2012 · 1 comment

Comments

@TrevorS
Copy link

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
Copy link
Contributor

avit commented Nov 14, 2013

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants