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">&#215;</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 

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

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -