1

I'm currently using rails form_for to build a form, but I would like know if there is a way to use an custom icon as buttons for the form instead of the button like the below image.

enter image description here ...

This is what I did but it doesn't work.

_form.html.erb

 <%= f.file_field :avatar, class: "test" %>  # 

.css

     .test {
    background: url('/images/icon.png') no-repeat left top;
}
laman
  • 552
  • 6
  • 18
  • Update button you can change by this css- input[type="submit"]{ background: url("icon.png"); } and for browse i am not sure because this whole is a one button including no file selected – neo-code Mar 28 '14 at 11:24
  • See This:http://stackoverflow.com/questions/1099702/file-field-browse-button-customize – Pavan Mar 28 '14 at 11:25
  • no its not that complicated as mention in above comments, its pretty simple http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-file_field please share corresponding HTML and please double check your css file/image path – Abubakar Mar 28 '14 at 11:47
  • Google search 'pretty file upload buttons' – yunzen Mar 28 '14 at 11:53
  • You cannot do it in Rails because each browser implements `` itself, including how the "browse" button looks. You have to do it in CSS instead - I used this article to make a solution: https://coderwall.com/p/4etjja –  Mar 28 '14 at 14:08

1 Answers1

0

I think the format of how you defined your class in ruby is incorrect. Try this link:

https://stackoverflow.com/a/5316059/3507417

or:

<%= f.file_field :avatar, :class => 'submit_class_name_here' %>
Community
  • 1
  • 1
atw
  • 5,428
  • 10
  • 39
  • 63