开发者

Radiant CMS: how to use form_for, fields_for inside radius tags

开发者 https://www.devze.com 2023-01-17 17:18 出处:网络
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

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.


You should be able to just include the Helper modules and use the helpers directly in the tag definition so something like this.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消