简体   繁体   English

使用变量预填充Rails HTML表单

[英]Pre-fill Rails HTML form with variable

I am trying to implement a pre-filled HTML form in Ruby on Rails where @product.price variable will be pre-filled. 我正在尝试在Ruby on Rails中实现一个预填充的HTML表单,其中@product.price变量将被预填充。 I don't really think a textarea is the one that I am looking for. 我真的不认为textarea是我想要的。

I have tried the following but it doesn't seem to be able to work. 我已经尝试了以下方法,但似乎无法正常工作。

<div class="field">
    <%= f.number_field :priceOffer, :input_html => {:value => @product.price }, class:"form-control" %>
</div>

Any suggestions why it couldn't work properly? 有什么建议为什么它不能正常工作?

如果查看number_field ,则在单个块中传递数字字段value,class和其他选项,因此请尝试以下操作:

<%= f.number_field :priceOffer, :value => @product.price, class:"form-control" %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM