2014-10-02 4 views
0

인터페이스의 Add whatever 버튼을 사용하여 하위 객체의 인스턴스를 여러 개 추가 할 수있는 Padrino에서 중첩 된 양식을 구현하려고합니다. I '는 f.fields_for (...) 블록 아무튼 대부가이 작업을 수행하려고 할 때, 그러나Padrino의 변수에 템플릿을 렌더링하는 방법은 무엇입니까?

def link_to_add_fields(text, f, association, target) 

    new_object = f.object.class.reflect_on_association(association).klass.new 
    template_path = "#{association}/fields" 

    template = f.fields_for(association, new_object) do |builder| 
    render(template_path, :f => builder) 
    end 

    link_to text, "#", onclick: "add_#{association}_fields(this, \"#{escape_javascript(template)}\", \"#{target}\")" 

end 

: 레일에서

는이 작업을 수행하는 한 가지 방법은 당신이 Add whatever 버튼을 클릭 때마다 중첩 된 필드를 생성하는 도우미를 만드는 것입니다 변수를 template 변수로 렌더링하지 않고 대신 레이아웃에 표시합니다.

저는 Padrino 프레임 워크에서 render_to_string 또는 비슷한 것을 찾으려고합니다.

누구든지이 문제를 어떻게 해결할 수 있는지 알고 있습니까? 감사합니다

답변

1

당신이 실패한 것은 render이 아니며, fields_for입니다. 그것은 잘못하여 erb 템플릿과 concat에서 호출되었음을 감지합니다.

erb에서 link_to_add_fields를 호출했기 때문에 본질적으로 사실이지만 erb에서 루비로 돌아가는 두 번의 다이빙을 추측 할 수있는 탐지 방법은 없습니다.

버그로 간주 될 수 있으며 여기서 https://github.com/padrino/padrino-framework 문제를 생성하고 잠긴 Gemfile이있는 최소한의 실패한 프로젝트를 제공 할 수 있습니다. 난 당신이 수동으로 다음과 같이 다시 루비 당신의 렌더링 엔진을 전환하고 제안 할 수있는 솔루션으로

:

def my_rendery_helper 
    @current_engine, engine_was = nil, @current_engine 
    template = fields_for(:moo) do |builder| 
     render('moo') 
    end 
    @current_engine = engine_was 
    template # now contains a SafeBuffer string 
    'result' 
    end 

@current_engine 내부 렌더링 엔진을 감지하는 데 사용되는 클래스 변수입니다.

+0

답장을 보내 주셔서 감사합니다. 나는 Padrino의 Github repo에 관한 이슈를 열어보고 사람들과상의 할 것입니다! – jdscosta91