0

I have a Rails (3.1) app with a model validation that, when triggered, puts the model and field name before the message, e.g.:

Profile image profile image content type Only jpeg, gif and png files are allowed for profile pictures

Is there a way to avoid that, so it reads:

Only jpeg, gif and png files are allowed for profile pictures

model.rb validation:
validates_attachment_content_type :profile_image,
  :content_type => ['image/jpeg', 'image/png', 'image/gif'],
  :message      => "Only jpeg, gif and png files are allowed for profile pictures"

The error appears as a part of this code in my layout:

<% if object.errors.any? %>
  <div class="alert alert-message error" data-alert="alert">
    <a class="close" data-dismiss="alert">×</a>
    <ul>
      <% object.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
    </ul>
  </div>
<% end %>
yellowreign
  • 3,528
  • 8
  • 43
  • 80

1 Answers1

0

My hunch is that msg is not actually the message but the entire error hash, and so calling <%= msg %> actually converts the whole hash to a string, including the keys. You could confirm this with <%= msg.class %>.

Assuming the view code you posted is a partial it would be helpful to see the view that includes the partial. If it's not a partial it would be useful to see the surrounding code.

Jordan Running
  • 102,619
  • 17
  • 182
  • 182
  • Sorry, I added the entire partial now – yellowreign May 24 '12 at 21:13
  • Oh, so you're passing the error in `flash`. How is it being set in your controller? Did you confirm what kind of object `msg` is? `msg.inspect` would be useful as well. – Jordan Running May 24 '12 at 21:19
  • sorry, i was looking at the incorrect partial (fixed my description). i found out when i put the commands you mentioned. with those, it returns: ActiveModel::Errors and # – yellowreign May 24 '12 at 21:38