2017-09-26 86 views
0

我申请我的产品形式的模板中选择价值,我会知道汽车在我的编辑形式汽车在形式

<div class="btn-group" data-toggle="buttons"> 
     <label class="btn btn-danger" style="margin-right: 10px;"> 
      <input id="bien_nb_piece_true" name="bien[nb_piece]" type="radio" autocomplete="off" value="0"/> Aucune 
     </label> 
     <label class="btn btn-danger" style="margin-right: 10px;"> 
      <input id="bien_nb_piece_true" name="bien[nb_piece]" type="radio" autocomplete="off" value="1"/> 1 
     </label> 
     <label class="btn btn-danger" style="margin-right: 10px;"> 
      <input id="bien_nb_piece_true" name="bien[nb_piece]" type="radio" autocomplete="off" value="2"/> 2 
     </label> 
     <label class="btn btn-danger" style="margin-right: 10px;"> 
      <input id="bien_nb_piece_true" name="bien[nb_piece]" type="radio" autocomplete="off" value="3"/> 3 
     </label> 
     <label class="btn btn-danger" style="margin-right: 10px;"> 
      <input id="bien_nb_piece_true" name="bien[nb_piece]" type="radio" autocomplete="off" value="4"/> 4 
     </label> 
     <label class="btn btn-danger" style="margin-right: 10px;"> 
      <input id="bien_nb_piece_true" name="bien[nb_piece]" type="radio" autocomplete="off" value="5"/> 5 et + 
     </label> 
     </div> 

如何选择定义值。如果我的产品的价值是1我想在1

+0

在你想要的输入类型上使用'selected'属性? –

回答

1

一个活性按钮可以使用checked属性,从数据库/控制器枢转关值的,如下所示:

<input <%= "checked" if product == 1 %> id="bien_nb_piece_true" name="bien[nb_piece]" type="radio" autocomplete="off" value="1"/> 
<input <%= "checked" if product == 2 %> id="bien_nb_piece_true" name="bien[nb_piece]" type="radio" autocomplete="off" value="2"/> 
<input <%= "checked" if product == 3 %> id="bien_nb_piece_true" name="bien[nb_piece]" type="radio" autocomplete="off" value="3"/> 

等。