I'm working on a bit of an extension for Radiant CMS that processes survey data. I'm trying to use form_for, fields_for and various helpers that rails provides inside pre-defined radius tags. These tags would generate the survey on Radiant pages.
Here's what I have in mind for integrating with 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>
So when I call <r:survey:form>, it suppose to generate <form> tag. I can do it by manually crafting the html, but I'd like to use form_for helper and the like.
Is there any way I could achieve the following:
# ------ <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
I hope that this explain what I'm trying to accomplish.