Rails validate_presence message - how to display? -
i have following in model attachments (i'm using paperclip):
class attachment < activerecord::base validates_presence_of :name validates_presence_of :attach_file_name, :message => "no file selected" has_attached_file :attach most error messages rails show @ top of screen using code that's in layouts:
<% flash.each |name, msg| %> <% if msg.is_a?(string) %> <div class="alert alert-<%= name == :notice ? "success" : "error" %>"> <a class="close" data-dismiss="alert">×</a> <%= content_tag :div, msg, :id => "flash_#{name}" %> </div> <% end %> <% end %> why isn't validate message showing up?
thanks help!!
update1
the attachment gets created attachments form _form.html.erb.
this in form:
<h4>attachment:</h4> <%= f.file_field :attach, :label => 'attachment' %>
in order test presence of file paperclip, try this:
class attachment < activerecord::base validates_presence_of :name validates_attachment_presence :attach, :message => "no file selected" has_attached_file :attach - https://github.com/thoughtbot/paperclip#usage
- https://makandracards.com/makandra/8043-validate-attachment-presence-using-paperclip
- conditional validation paperclip difficult
also, rails 3 -way validates following:
class attachment < activerecord::base validates :name, presence: true validates :attach, attachment_presence: true, message: 'no file selected!' has_attached_file :attach
Comments
Post a Comment