0

我的会话中存储了以下内容:

session[:quoteResponse]['6000']['something'][...]
session[:quoteResponse]['6000']['something_else'][...]

session[:quoteResponse]['8000']['something'][...]
session[:quoteResponse]['8000']['something_else'][...]

session[:quoteResponse]['10000']['something'][...]
session[:quoteResponse]['10000']['something_else'][...]

我如何遍历它们以实现以下目标?

<div class="product">
    <%= radio_button_tag 'form[baseMiles]', '6000' %>
    <label for="form_baseMiles_6000">6,000 Policy Miles</label>
    <a class="need-more-miles" href="#">Need more miles? <span>View</span></a>
</div>

<div class="product">
    <%= radio_button_tag 'form[baseMiles]', '8000' %>
    <label for="form_baseMiles_8000">8,000 Policy Miles</label>
    <a class="need-more-miles" href="#">Need more miles? <span>View</span></a>
</div>

<div class="product">
    <%= radio_button_tag 'form[baseMiles]', '10000' %>
    <label for="form_baseMiles_10000">10,000 Policy Miles</label>
    <a class="need-more-miles" href="#">Need more miles? <span>View</span></a>
</div>
4

2 回答 2

1

好吧,取决于 'something' 和 'something_else' 应该去哪里,你可以

<% session[:quoteResponse].each do |num, arr| %>
  <% arr.each do |item| %>
    ...
    here you can use num to refer to 6000, 10000 and item to each 'something', 'something_else'
    ...
  <% end %>
<% end %>

我希望这有帮助。

于 2012-07-09T09:48:42.237 回答
1

我不明白为什么这不起作用

<% session[:quoteResponse].each do |miles, other_properties| %>
  <div class="product">
    <%= radio_button_tag 'form[baseMiles]', miles.to_s %>
    <label for="form_baseMiles_<%= miles %>"><%= miles %> Policy Miles</label>
    <a class="need-more-miles" href="#">Need more miles? <span>View</span></a>
  </div>
<% end %>

其他属性将包含“something”和“something else”作为哈希值,以备不时之需。

于 2012-07-09T09:51:12.477 回答