0

我目前正在为房地产应用程序构建 XML 导出。在 Rails 中使用 Builder gem。我正在寻找一种方法来执行以下操作:

<commercialRent>
  "commercialRent figure"
  <range>
    ...
  </range>
</commercialRent>

我似乎找不到实现“文本在此处”部分的方法

我的代码:

b.commercialRent(period: "annual", plusOutgoings: self.plus_outgoings) {  
      self.rent_price;
        b.range { 
          b.min(self.rent_psm_pa_min); 
          b.max(self.rent_psm_pa_max)
      };
    };

回报:

<commercialRent period="annual" plusOutgoings="no">
  <rentPerSquareMeter>
    <range>
      <min>1000</min>
      <max>10000</max>
    </range>
  </rentPerSquareMeter>
</commercialRent>

一切都打印正常,除了 self.rent_price 丢失。我想不通。

4

1 回答 1

0

您使用该text!方法生成一个文本节点:

- (对象)文本!(文本)

将文本附加到输出目标。转义任何标记。可以在标记括号内使用:

builder.p { |b| b.br; b.text! "HI" }   #=>  <p><br/>HI</p>

所以这样的事情应该可以解决问题:

b.commercialRent(period: "annual", plusOutgoings: self.plus_outgoings) do
  b.text! self.rent_price
  #...
end
于 2013-09-04T03:15:14.623 回答