2008-10-21 7 views
1

레거시 데이터베이스에서 작동하고 멋진 CRUD 인터페이스에 ActiveScaffold 플러그인을 사용하는 RoR 애플리케이션을 개발 중입니다.Ruby On Rails에서 ActiveScaffold를 사용하는 복합 키

그러나 레거시 db 테이블 중 하나에는 복합 기본 키가 있습니다. 나는 그것을 처리하기 위해 복합 키 플러그인을 사용했지만, 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의 핵심 개발자가 모니터하는 가장 좋은 방법은 ActiveScaffold Google Group입니다. 궁극적으로 문제를 해결하고 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

나는이 기능을 읽기 전용 모델로, 기존 DB에서 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 블록에서 다음과 같습니다

config.actions.exclude :create, :update, :delete 
관련 문제