Podczas submitu formularza nie wyświetla się błąd dla validacji rozmiaru pliku, natomiast w przypadku braku pliku jest ładnie pokazany błąd.
Oto kod formularza i modelu:
[code=ruby]<%= simple_form_for @document, url: jakistamurl(), html: {class: ‘form-horizontal’, multipart: true} do |f| %>
<%= f.input :description, as: :text, input_html: {rows: 3, class: 'span4'} %>
<%= f.input :attachment, as: :file %>
<%= f.button :submit, 'Upload' >
<% end %>
class Document < ActiveRecord::Base
has_attached_file :attachment
validates_attachment_presence :attachment
validates_attachment_size :attachment, less_than: 5.megabytes, message: ‘is too big’[/code]
Obszedłem to następującym hackiem w before_validation
if self.errors[:attachment_file_size].present?
self.errors[:attachment] << self.errors[:attachment_file_size].to_sentence
end
jednak nie jest to idealne rozwiązanie