I'm new to rails and ActiveScaffold and wondering whether there's an elegant
way to include columns from an associated model in both a model's list/index
AND that table's search.
When A belongs_to B and listing A, I would like to include columns B.foo and
B.bar in the table (and the search-functionality). Right now, I create a
helper in A's model for every column in B that I want to show, e.g.:
def foo
B.foo
end
And when B.bar is a belongs_to association with model C (B.bar_id pointing to
a C-id), I'd do e.g.
def bar
B.bar.name
end
In A's controller, I'd have
class A < ApplicationController
active_scaffold :a do |config|
#config.list.columns.exclude :B
config.columns << :foo
config.columns << :bar
config.columns[:foo].search_sql = 'B.foo'
config.columns[:bar].search_sql = 'B.bar.name'
end
end
Not only is this a rather tedious way to add columns, searching for "test"
does not show a record of A, even though A.B.bar.name is "test". Neither do I
find a 'WHERE ...name LIKE "%test%"' in script/server's console, so I must
have misunderstood something.
Why doesn't searching find the record being associated to the "test"-record?
And, can I maybe write something like
config.columns << :B.bar.name
config.columns[:B.bar.name].search_sql = 'B.bar.name'
Thanks for your help!
ben
--
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/activescaffold?hl=en.