Question

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

In consumers_controller I am trying to include some field from agency

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

There are such associations Agency -> Event -> Consumer. And there is no association between agency and consumer, only through event.

but it causes an error.

How Can I include to list a any field form agency table?

Was it helpful?

Solution 2

Solution was a quite simple but most likely inefficient.

I have added a method to Consumer model:

class Consumer < ActiveRecord::Base
  ...

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

Then I have added a virtual column to list:

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

That's all.

OTHER TIPS

According to the wiki, I think what you want is this:

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

Also, make sure a consumer has an agency association or column.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top