2010-09-24 58 views
1

我正在處理一些Radiant CMS的擴展,它處理調查數據。我正在嘗試使用form_for,fields_for和rails在預定義的半徑標籤內提供的各種幫助程序。這些標籤會在Radiant頁面上生成調查。Radiant CMS:如何使用form_for,fields_for內部半徑標記

這就是我心目中的光芒四射的整合:

<r:survey id="200"> 
    <r:survey:form>     #<-- call to form_for 
    <r:survey:questions:each>  # <-- calls fields_for 
     <r:question>    # <-- renders question 
     <r:answer_field>   #<-- renders input via text_field, text_area, etc 
    </r:survey:questions:each> 
    </r:survey:form> 
</r:survey> 

所以,當我打電話< R:調查:形式>,它想產生<形式>標籤。我可以通過手工製作html來完成,但我想使用form_for helper等。

有沒有什麼辦法可以實現以下目標:

# ------ <r:survey:form> ----------------------------- 
    tag 'survey:form' do |tag| 
    # call form_for which would render form header and open <form> tag 
    tag.expand 
    # form_for would end here, closes </form> 
    end 

# ------ <r:survey:questions>---------------------------- 
    tag 'survey:questions' do |tag| 
    tag.expand 
    end 

# ------ <r:survey:questions:each>------------------------ 
    tag 'survey:questions:each' do |tag| 
    result = [] 
    survey = tag.locals.survey 
    # should call fields_for here 
    survey.survey_questions.sort_by{|q| q.order}.each do |question| 
     tag.locals.question = question 
     result << tag.expand 
    end 
    # end of fields_for 
    result 
    end 

我希望這個解釋我試圖完成。

+0

這個問題有什麼好運? – Trip 2011-03-06 16:58:11

+0

我能想到的最好的方法是在標籤塊內調用渲染模板,如下所示:'response.template.render:partial =>'partial_name',:locals => {:var => val,:tag => tag} ' 然後在部分內部調用'tag.expand'來擴展任何內部標籤。不優雅,但它的作品。 – Swartz 2011-03-07 05:17:13

回答

2

你應該能夠只包含Helper模塊並直接在標籤定義中使用helpers,就像這樣。

module CustomTags 
    include Radiant::Taggable 
    include ActionView::Helpers::TagHelper 
    include ActionView::Helpers::AssetTagHelper 

    tag "my_tag" do |tag| 
    javascript_include_tag :some_js_file 
    end 
end 
相關問題