2008-10-21 18 views
1

我正在開發與舊數據庫一起工作的RoR應用程序,並使用ActiveScaffold插件來創建奇特的CRUD界面。在Ruby On Rails中使用ActiveScaffold的組合鍵

但是,我的遺留數據庫的表中有一個表具有複合主鍵。我試着使用組合鍵的插件來處理它,但它似乎有衝突與ACtiveScaffold:我收到以下錯誤:

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' 

在型號代碼水木清華有喜歡同時:

set_primary_keys :contact, :type 

我高度讚賞任何想法如何我可以用ActiveScaffold獲得組合鍵功能。

回答

2

我認爲您最好的選擇可能是檢查ActiveScaffold Google Group,因爲它由ActiveScaffold的核心開發人員監控,他們最終能夠解決您的問題並解釋爲什麼組合鍵與插件無法與ActiveScaffold一起使用。

祝您好運,如果您確實從Google小組獲得結果(我之前發佈並很快收到反饋),請務必發佈後續行動。

我找到的一個快速結果是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.

這可能會爲你做。

0

不,我還沒有收到任何回覆,我不確定ActiveScaffold是否被主動維護。

經過一段時間玩ActiveScaffold後,我從頭開始實施我自己的CRUD界面。

0

我有這個工作,只讀模型,使用ActiveScaffold在遺留數據庫上。

訣竅是覆蓋模型中默認的'id'字段並返回連接的PK字符串。

如果這是夠好,那麼在這裏你去:

class CPKReadonlyModel < ActiveRecord::Base 
    set_primary_key :id_one # only half of it, but id overridden below... 

    def id 
     self.id_one.to_s + ',' + self.id_two.to_s 
    end 

    def readonly? 
     true 
    end 

    def before_destroy 
     raise ActiveRecord::ReadOnlyRecord 
    end 

    def delete 
     raise ActiveRecord::ReadOnlyRecord 
    end 

    def self.delete_all 
     raise ActiveRecord::ReadOnlyRecord 
    end 
    end 

該控制器具有在active_scaffold配置塊如下:

config.actions.exclude :create, :update, :delete