Ruby on Rails 中文本区域的最大长度 [英] Maximum length on a textarea in Ruby on Rails

查看:46
本文介绍了Ruby on Rails 中文本区域的最大长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 textarea<上应用 :maxlenght => 40/a> 在我的表格上.但它没有成功.我们可以对 textarea 设置长度限制吗?

I tried applying the :maxlenght => 40 on a textarea on my form. But it didn't work out. Can we have a length limit on a textarea?

文本区域的代码是

<%= f.text_area :data,
                :rows => 2,
                :cols => 60 ,
                :maxlength => 140,
                :autocomplete => :off,
                :class => "textareabytes" %>

推荐答案

就像 Rahul 说,HTML 中的 textarea 没有 maxlength 属性.只有 text input 有那个.

Just like Rahul said, there's no maxlength attribute for textarea in HTML. Only text input's have that.

您需要记住的是,RoR 的 text_area 函数(以及所有 RoR 的 HTML 生成器函数)接受您提供给它们的任何参数.如果他们不识别该参数,则将其转换为 HTML.

The thing you need to remember, is that RoR's text_area function (and all of RoR's HTML-generator functions) accept any argument you'll give them. If they don't recognized the parameter, then the'll just convert it to HTML.

<%=f.text_area :data, :hellothere => "hello to you too"%>

将输出此 HTML:

<textarea name="data" hellothere="hello to you too"></textarea>

我知道这很难记住,但 Ruby on Rails 并不神奇,它只是为您做了很多事情.诀窍是知道它是如何工作的,这样您就可以了解它们为什么起作用,以及在它们不起作用时如何修复它们!

I know it's hard to remember, but Ruby on Rails isn't magic, it just does a lot of things for you. The trick is to know how it does them, so you can understand why they work, and how to fix them when they don't!

这篇关于Ruby on Rails 中文本区域的最大长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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