field_search association

46 views
Skip to first unread message

JB

unread,
May 8, 2012, 11:08:11 AM5/8/12
to ActiveScaffold : Ruby on Rails plugin
I have a simple model where I have:

class SubContractor < ActiveRecord::Base
has_many :contacts, :dependent => :destroy
end

class Contact < ActiveRecord::Base
belongs_to :sub_contractor
end

The Contact model has a cost_code column. I need to add the ability to
search on the cost_code to the sub_contractor field_search form. Can
anyone point me in the right direction on this?

Thanks!

ser...@entrecables.com

unread,
May 8, 2012, 9:01:58 PM5/8/12
to actives...@googlegroups.com
On Tue, 8 May 2012 08:08:11 -0700 (PDT), JB <jeff.ba...@gmail.com>
wrote:
It's explained in wiki, but I include a summary here:

Add a virtual column named cost_code to the SubContractor model and
controller. ActiveScaffold needs your model responds to the column name,
because it will call that method in a new record.

class SubContractor < ActiveRecord::Base
has_many :contacts, :dependent => :destroy
def cost_code; end
end

class SubContractorsController < ApplicationController
active_scaffold do |config|
config.columns << :cost_code
config.columns.exclude :cost_code # you don't want it in most
actions
...
config.columns[:cost_code].includes = :contacts
config.columns[:cost_code].search_sql = 'contacts.cost_code'
config.field_search.columns << :cost_code
end
end

Reply all
Reply to author
Forward
0 new messages