在Ruby on rails中,如何设置表的列宽 [英] In Ruby on rails, how to set Column widths of a table
本文介绍了在Ruby on rails中,如何设置表的列宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Ruby的新手,在设置表格的列宽方面遇到了麻烦。
我生成一个word文档(RoR app),其中我有多个表,我使用com.lowagie.text.Table。
但是,我无法更改表格列的宽度。
解决方案
需要一些更多细节。根据你的问题,我认为你必须通过模型设置列长度。
假设我们有一个名为customer.rb
的模型,我们有一个列名first_name,我们必须设置它的最大值长度为30个字符。
如果长度超过30个字符,则应显示错误消息。
所以我们必须这样做 -
验证:first_name,presence:{message:' 请输入您的名字。'}
验证:first_name,:length = > {:maximum = > 30 ,:message = > ' 请输入长度不超过30个字符的名字。'}
希望这会有所帮助!! :)
Hi,
I am new to Ruby on rails and facing trouble in setting the column width of the table.
I am generating a word document (RoR app) where I have multiple tables and I use "com.lowagie.text.Table".
However, I am not able to change the width of the table column.
解决方案
Need some more details. According to your question I think you have to set the column length through model.
Let's say we have a model called customer.rb
and we have a column name "first_name" and we have to set its maximum length to 30 characters.
If the length exceed 30 characters then a error message should be shown.
So we have to do like this-
validates :first_name, presence: { message: 'Please enter your First Name.'} validates :first_name, :length => { :maximum => 30, :message => 'Please enter a First Name of 30 characters or less in length.' }
Hope this will help!! :)
这篇关于在Ruby on rails中,如何设置表的列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文