我有一个 form_for 按以下方式编写:
<div class="field">
<%= location.label :city %>
<%= location.text_field :city, :disabled=>true%>
</div>
<div class="field">
<%= location.label :country %>
<%= location.text_field :country, :disabled=>true%>
</div>
正如您所看到的,2 个文本字段被禁用,因为它们是由 jquery 函数自动填充的,我不想让用户处理它们。 问题是,通过这种方式, View 不会将该参数传递给 Controller ,因为它们被禁用了! 有没有其他方法可以将不可编辑的 text_field 传递给 Controller ,注意我不想使用隐藏字段,因为我想在文本框中向用户显示结果
TNX
最佳答案
将其设置为只读!
<%= location.text_field :country,:readonly => true%>
关于ruby-on-rails - Rails 不可编辑文本字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5620128/