Just circling back with resolution of this question in case it helps
anyone else out.
Primary problem were the primary keys in the model associations:
class Instance < ActiveRecord::Base
has_one :elb
end
class Elb < ActiveRecord::Base
belongs_to :instance
end
I expected the default primary key for elb to be the name of the child
class and "_id", i.e., "instance_id". Unfortunately, as some debugging
in the console showed, Rails was looking for "instance.id", not
"instance.instance_id". So a couple of quick edits fixed the problem
with the "Create New" links appearing, rather than the associated
values.
class Instance < ActiveRecord::Base
has_one :elb,
:primary_key => 'instance_id'
end
class Elb < ActiveRecord::Base
belongs_to :instance,
:primary_key => 'instance_id'
end
Now, having the Elb model's data in the Instance table still required
a virtual column, which was achieved following the very helpful advice
online on this group and the API--so I take no credit.
In the Instance model:
def elb_column
@elb = Elb.find(:first, :conditions => ["instance_id = ?",
instance_id ])
@elb.elb_id if @elb
end
And in the instances_controller, I added the following:
conf.columns.add :elb_column
conf.list.columns.exclude :elb_column #also excluded :elb_column from
update and show and new
conf.columns[:elb].actions_for_association_links = [:list] #To remove
the "Create New" icons when elb values were nil
conf.search.columns.add :elb_column
conf.columns[:elb_column].search_sql = "elbs.elb_id"
SQL command upon submitting a search JOINed the instances and elbs
tables before doing a LIKE for the search value (via fixing the
primary key problem) and searched within the elbs.elb_id column (via
the .search_sql method).
Kaboom! Obviously there's still some tweaking to be done, but thanks
to everyone who helped out!
Jay
--
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.