Is it possible to provide your own caption for the button that the file_field helper generates?
Asked
Active
Viewed 7,654 times
4
-
1@Layke - It shows you don't know rails, your answer is completely wrong. Please refrain from answering questions you have no idea about. – herbil Oct 25 '12 at 11:14
-
1@Mukul Goel - Please don't just jump on the band wagon, evaluate the merit of others comments yourself rather than taking them as gospel. The previous commenter did not have the answer. – herbil Oct 25 '12 at 11:17
-
I believe this is a html question, and not a rails helper question. As mentioned in the answer below, it's not really possible without some hacks. As to the reply by @Layke, he has no idea what he is talking about, I'll highlight is answer to an admin. – dangerousdave Oct 25 '12 at 11:24
-
Removed ambiguous/wrong comment. – Layke Oct 25 '12 at 11:25
-
2@MukulGoel - an apology would go a long way, or please justify why your comment is still relevant. – herbil Oct 25 '12 at 11:29
-
@herbil : My comment is not relevant anymore and I am removing it. Thank you for bringing it up and I apologize for jumping to conclusion. :-) #Peace. Welcome to SO. – Mukul Goel Oct 25 '12 at 12:08
3 Answers
4
You can check this answer for your case: How to change the button text of <input type="file" />?
The answer will show you how to do it which you can implement in rails views.

Community
- 1
- 1

HungryCoder
- 7,506
- 1
- 38
- 51
1
Also some tips here: file_field Browse button customize, quirksmode

Community
- 1
- 1

Paweł Damasiewicz
- 23
- 7
0
Sadly, the rails helper doesn't really allow you to change the text by default. You may tweak it using CSS.
html.erb file
<%= file_field_tag "file", class: "inputfile" %>
<%= label_tag :file, "Any text here", class: "btn btn-primary" %>
css file
.inputfile {
width: 0.1px;
height: 0.1px;
opacity: 0;
overflow: hidden;
position: absolute;
z-index: -1;
}
Here's a preview:
If you want more customisation this is a great guide!

Lea Tinoso
- 1,663
- 2
- 6
- 14