Virtual column value not displayed properly

2 views
Skip to first unread message

David

unread,
Jan 31, 2008, 2:30:58 PM1/31/08
to ActiveScaffold : Ruby on Rails plugin
I've defined a virtual column in my model like this:

class Contact < ActiveRecord::Base
has_many :artist_items, :class_name => "Item", :foreign_key =>
"artist_id"
has_many :buyer_items, :class_name => "Item", :foreign_key =>
"buyer_id"

def full_name_last
last_name + ", " + first_name
end
end

I want to show it in the list view as a sortable column, so I wrote
the controller like this:

class ContactController < ApplicationController
active_scaffold :contacts do |config|
config.columns =
[:full_name_last, :first_name, :middle_name, :last_name, :email, :comments, :artist_items]
config.columns[:full_name_last].label = "Contact"
columns[:full_name_last].sort_by :sql => "concat(last_name, ', ',
first_name)"
end
end


This works fine, but when I'm on the edit view, the status header at
the top of edit section says "Update#Contact0x46d5764>" instead of the
full name. When I create a column in the Item list view for the
artist, this same value appears instead of the full name.

How can I get the full name to show up properly?

Thanks
David

Sergio Cambra

unread,
Jan 31, 2008, 3:37:29 PM1/31/08
to actives...@googlegroups.com

That's because you don't have methods to_label, name, label or title, so
to_s is used. In http://www.activescaffold.com/tutorials/to_label you can
see the methods used to show a description of a record.
You can define to_label as:
alias_method :to_label, :full_name_last
or
def to_label
full_name_last
end

David

unread,
Feb 10, 2008, 4:49:29 PM2/10/08
to ActiveScaffold : Ruby on Rails plugin
Thanks, that worked!

David

On Jan 31, 3:37 pm, Sergio Cambra <ser...@ensanjose.net> wrote:
> El Jueves, 31 de Enero de 2008, David escribió:
>
>
> That's because you don't have methods to_label, name, label or title, so
> to_s is used. Inhttp://www.activescaffold.com/tutorials/to_labelyou can
Reply all
Reply to author
Forward
0 new messages