2013-04-23 4 views
6

मैं निम्नलिखित मॉडलकैसे सौंप खेतों पर लूटना उपयोग करने के लिए

class Position < ActiveRecord::Base 

    belongs_to :position_name 
    delegate :name, to: :position_name 

और इस खोज फ़ॉर्म

= search_form_for @search, url: '#', method: 'GET', html: {id: nil, class: "term_search_form"} do |f| 
     = f.text_field :name_cont, class: 'search-query', id: nil, placeholder: t('search') 

और मैं अभी भी यह त्रुटि संदेश प्राप्त:

undefined method `name_cont' for #<Ransack::Search:0x007f97187c5b80> 

मुझे लगता है कि यह प्रतिनिधि विधि नाम के कारण है।

मैं प्रतिनिधि तरीकों पर रंसैक का उपयोग कैसे कर सकता हूं?

+0

समान समस्या का उपयोग करना चाहिए –

उत्तर

6

यह थोड़ी देर का उत्तर है, लेकिन शायद यह किसी और की मदद करेगा। तो, मुझे एक समान समस्या थी।

मेरे पास 3 मॉडल थे: क्षेत्र, भवन और उत्पाद, जहां क्षेत्र has_many :buildings, भवन has_many :products। मेरे उत्पाद मॉडल में मैंने delegate :area_id, to: :building का उपयोग किया।

मैंने नाम, क्षेत्र, भवन जैसे क्षेत्रों जैसे किसी उत्पाद को खोजने के लिए रंसैक का उपयोग किया। मेरी नियंत्रक की कार्रवाई @search चर में जुड़े शामिल Buiding मॉडल, इस तरह:

@search = Product.includes(:building).search(params[:q])

तो मेरी search_form

= search_form_for @search, url: user_products_path do |f| 
    %td 
    %td= f.text_field :name_cont, class: "form-control", placeholder: t('.name') 
    %td= f.select :building_area_id_eq, options_for_select(Area.data_for_select(true), q_param(:building_area_id_eq)) 
    %td= f.select :building_id_eq, options_for_select(Building.data_for_select(true), q_param(:building_id_eq)) 

है की तरह था, यदि आपका नियंत्रक में आप जुड़े मॉडल शामिल हैं: position_name , आपके विचार से आपको = f.text_field :position_name_name_cont

+0

क्या उपसर्ग के बिना ऐसा करने का कोई तरीका है? पसंद: area_id_eq। – HFX

+0

@ एचएफएक्स मुझे ऐसा नहीं लगता है –

संबंधित मुद्दे