Let’s suppose I have a form in views/users/new.html.erb, and:
:first_name field has validates :presence => true
:gender in mysql database field can have boolean values (0-Female,
1-Male)
:avatar has a binary field in mysql database
<%= form_for(@user) do |f| %>
<%= f.text_field :first_name %>
<%= f.text_field :second_name %>
…else fields which need to validate
<%= f.select :gender, [[‘Select’,nil],[‘Male’, 1],[‘Female’, 0]] %>
<%= f.file_field :avatar %>
<%= f.submit “Add” %>
<% end %>
When I am not put anything to first_name field, but fill in 3
others(second_name, select and photo), I see error message and
second_name still filled in, but avatar and gender field is empty now.
What’s matter?
Assume I load image avatar to database. How I can load it from db?
…else fields which need to validate
<%= f.select :gender, [[‘Select’,nil],[‘Male’, 1],[‘Female’, 0]] %>
<%= f.file_field :avatar %>
<%= f.submit “Add” %>
<% end %>
When I am not put anything to first_name field, but fill in 3
others(second_name, select and photo), I see error message and
second_name still filled in, but avatar and gender field is empty now.
What’s matter?
AFAIK file fields don’t restore the state from one request to the next.
So the user will have to reselect the file in case errors occur in the
initial request. Note: I could be mistaken on this.
Assume I load image avatar to database. How I can load it from db?
Have you looked at the Paperclip gem. It should make dealing with file
uploads easier.