displaying value of associated model

8 views
Skip to first unread message

slava

unread,
Sep 22, 2011, 2:06:36 AM9/22/11
to ActiveScaffold : Ruby on Rails plugin
Hello,
I want to display value from associated model in a column of an
active_scaffold

class TermsController < ApplicationController
active_scaffold :terms do |config|
config.columns = [
...
:market.volume
]
end
end

class Terms < ActiveRecord::Base
has_one :market
end

What is the correct way to specify the column to show up in scaffold?

Atastor

unread,
Sep 22, 2011, 2:51:31 AM9/22/11
to actives...@googlegroups.com
Controller Terms:

...
config.columns=[...,:market_volume,...]
...

Model Terms:

def market_volume
  self.market.volume
end

Atastor

unread,
Sep 22, 2011, 2:54:24 AM9/22/11
to actives...@googlegroups.com
and if you want to add a setter add the following, too:

def market_volume=(value)
  self.market.volume=value
end

I intentionally left out all of the safeguards, you better insert (like nil-checks etc.).

Reply all
Reply to author
Forward
0 new messages