Configure Node Names in Ruby Builder

I am creating a tool that generates dynamic xml. As a result, my models have fairly common names:

Project 
  has_many    :Groups

Group
  has_many    :Items
  has_many    :Groups
  belongs_to  :Project

Item
  has_many    :Params
  belongs_to  :Group

Param
  belongs_to  :Project
  belongs_to  :Group
  belongs_to  :Item

Therefore, when I create xml from the project controller, the project name node is the root of the node for xml. But I do not want this to be called a "project." I want node to be any value @ project.params ['name'].

The problem I am facing is that the structure of the builder makes it difficult ... When I do this:

xml.project do
  ~some code
end

... He will always create a "project" as the root name of the node. I cannot find a way to override it to use a different name. I was hoping the following would work:

xml.send(@project.params.name) {
  ...some code
}

.. . , params. .

+3
1

xml.project :

xml.tag! @project.params.name do

, .

+6

Source: https://habr.com/ru/post/1728508/


All Articles