Rails不可编辑文本字段 [英] Rails not editable text field

查看:64
本文介绍了Rails不可编辑文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个form_for以下列方式编写:

I have a form_for written in the following manner:

<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函数自动填充,并且我不想让用户处理它们. 问题在于,以这种方式,视图不会将参数传递给控制器​​,因为已将其禁用!!! 还有其他方法可以将不可编辑的text_field传递给控制器​​,请注意我不想使用隐藏字段,因为我想在文本框内向用户显示结果

As you can see the 2 textfield are disabled because they are autofilled by a jquery function and I don't want let the user handle them. The problem is that in this way, the view doesen't pass that parameters to the controller because are disabled !!! Is there any other way to pass not editable text_field to the controller, taking care that I don't want to use hidden field because I want to show the results to the user inside a textbox

TNX

推荐答案

设为只读!

<%= location.text_field :country,:readonly => true%>

这篇关于Rails不可编辑文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆