views:

762

answers:

2

I am developing RoR application that works with legacy database and uses ActiveScaffold plugin for fancy CRUD interface.

However one of the tables of my legacy db has composite primary key. I tried using Composite Keys plugin to handle it, but it seems to have conflicts with ACtiveScaffold: I get the following error:

ActionView::TemplateError (Could not find column contact,type) on line #3 of ven
dor/plugins/active_scaffold/frontends/default/views/_form.rhtml:
1: <ol class="form" <%= 'style="display: none;"' if columns.collapsed -%>>
2:   <% columns.each :for => @record do |column| -%>
3:   <% if is_subsection? column -%>
4:   <li class="sub-section">
5:     <h5><%= column.label %> (<%= link_to_visibility_toggle(:default_visible =
> !column.collapsed) -%>)</h5>
6:     <%= render :partial => 'form', :locals => { :columns => column } %>

vendor/plugins/active_scaffold/lib/data_structures/sorting.rb:16:in `add'

while having in model code smth like:

set_primary_keys :contact, :type

I highly appreciate any idea how I can get composite keys capability with ActiveScaffold.

+2  A: 

I think your best bet may be checking the ActiveScaffold Google Group as it's monitored by core developers of ActiveScaffold and they would ultimately be able to solve your problem and explain why composite keys with the plugin won't work with ActiveScaffold.

Good luck and be sure to post a follow-up if you do get results from the Google Group (which I have posted on before and received feedback very quickly).

One quick result I did find was this.

What I did was to create a facade class that does not inherit from
ActiveRecord then make the "id" show the primary key. In my case the
primary key was computed from other data and could change as a result
of an edit, so I had to override ActiveScaffold in a few places to
allow for the primary key changing after an update. But, all in all
it works and is fairly straightforward. Start with an empty class
and just resolve messages that are not understood. In your case you
could even just redirect all messages to a wrapped ActiveRecord while
replacing the id and id= methods, and filtering the [] and []= methods.

That may do the trick for you.

mwilliams
A: 

No, I have not received any reply from the group and I am not sure if ActiveScaffold is actively maintained yet.

After some time playing with ActiveScaffold, I ended up implementing my own CRUD interface from the scratch.

Maxim Ananyev