我正在研究处理调查数据的Radiant CMS的一些扩展。我正在尝试使用form_for,fields_for和rails提供内部预定义半径标记的各种帮助程序。这些标签将在Radiant页面上生成调查。
以下是我与Radiant整合的想法:
<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>
所以,当我打电话给&lt; r:survey:form&gt;时,它假设生成&lt; form&gt;标签。我可以通过手工制作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 :(得分:2)
您应该能够只包含Helper模块并直接在标记定义中使用帮助程序,如下所示。
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