2013-02-05 142 views
1
class Agency < ActiveRecord::Base 
    has_many :events 

    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable 

    attr_accessible :name, :email, :phone, :address, :city, :state, :zip, 
        :notes, :is_admin, :password, :password_confirmation, :remember_me 
end 

class Event < ActiveRecord::Base 
    belongs_to :agency 
    has_many :consumers 
end 

class Consumer < ActiveRecord::Base 
    belongs_to :event 
end 

在consumers_controller我想包括来自机构一些领域Active_scaffold添加到列表关联表列

active_scaffold :consumer do |conf| 
    list.columns = [ 
     :agency, :event 
    ] 
end 

有这样的协会机构 - >事件 - >消费。机构和消费者之间只有通过事件才有关联。

但它会导致错误。

如何包含列出任何字段表单代理表?

回答

0

解决方案很简单,但很可能是效率低下。

我已经加入到消费模型的方法:

class Consumer < ActiveRecord::Base 
    ... 

    def agency_name 
    self.event.agency[:name] 
    end 
end 

然后我添加了一个虚拟列列出:

list.columns = [ 
    :agency_name, :event, ... ] 

这就是全部。

+0

如何在event.agency.name上实现搜索? – aashish

+0

@aashish,你是什么意思?如何在event.agency.name上添加active_scaffold搜索字段?或者只是建立ActiveRecord查询? –

+0

如果你的意思是第一个,那么通过API列的可能决定是 'class ConsumersController

0

按照wiki,我想你想要的是这样的:

active_scaffold :consumer do |conf| 
    conf.columns = [:agency, :event] 
end 

此外,确保消费者有一个机构协会或列。

+0

问题是**消费者**只有通过**活动**表与**代理**有关联。 –