在rails的file_field标签中添加size选项 [英] adding size option to file_field tag in rails

查看:124
本文介绍了在rails的file_field标签中添加size选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

回答

我在提出问题时实际上找到了答案,但是我以任何方式发布它,因为有些人可能认为这很有用(如此处所述:

I actually found the answer while formulating the question but I'm posting it any way since some might find this useful(as said here: https://meta.stackexchange.com/questions/49922/should-i-continue-adding-a-question-if-i-have-found-the-answer-myself)

我在将大小添加到ROR3中的文件字段时遇到麻烦.这是我的语法:

I'm having trouble adding size to a file field in ROR3. Here was my syntax:

= f.file_field :file, :size => "11"

这不会出现,但是会创建一个带有以下内容的文件输入字段:

this doesnt appear but creates an file input field with this:

<input type="file" name="soap_test_zip_file[file]" id="soap_test_zip_file_file">

现在我知道我以前可以使它工作,所以我研究了一些旧代码并发现了这一点:

now I KNOW I made it work before so I looked into some old code and found this:

= file_field_tag :file, :size => 11

输出以下内容:

<input type="file" size="11" name="file" id="file">

这给了我正确的大小,但是文件ID和名称错误.所以我尝试了这个:

which gives me the correct size, but the wrong file id and name. So I tried this:

<input type="file" size="11" name="soap_test_file_file" id="soap_test_file_file">

这给了我正确的ID,但有错误的名字.问题是如何重现该file_field但大小如何?

which gives me the RIGHT ID, but the WRONG NAME. Question is how do I reproduce that file_field but with the size?

我调查了Ryan Bigg的回答:

I looked into this answer by Ryan Bigg btw: Problem showing the 'size' attribute for a 'file_field' using Ruby on Rails 3

,他说的是跨浏览器,它们以不同的方式呈现文件字段.确实是这样,但是如果浏览器可以处理,我想呈现一个简短的文件字段.

and he's saying it's a cross browser thing that they render file fields differently. That is the case, but I would like to render a short file field IF the browser can handle it.

推荐答案

我使用过:

= file_field_tag :soap_test_zip_file, {:name => 'soap_test_zip_file[file]', :size => 11}

这使我可以覆盖(控制器的)名称和大小

This made me override the name(for the controller) and the size

这篇关于在rails的file_field标签中添加size选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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