I have a form that looks like this –
<%= form_for @photo,:html=>{:multipart=>true} do |f| -%>
<div>
<%= f.file_field :photo %>
<%= f.submit "Upload", :disable_with => 'Uploading...' %>
</div>
<%= @photo.errors[:photo].each do |attr,msg| %>
<span class="form-error"><%= msg %></span>
<% end %>
<% end -%>
My model has the following line
validates_presence_of :photo, :message => "Choose a file to upload"
For some reason the error message is rendering outside of containing span. The rendered HTML looks like this –
<form ..some attributes..><some hidden divs and inputs />
<div class="field_with_errors"><input type="file" name="photo[photo]" id="photo_photo"></div>
<input type="submit" value="Upload" name="commit" id="photo_submit" data-disable-with="Uploading...">
<span class="form-error"></span>
Choose a file to upload
</form>
I’m very new to rails, but this seems odd to me.
Why is my message outside of it’s container?
Thanks.
Shouldn’t this NOT have an equal sign (you like my double negative there)?
In other words, it should be:
I’ve made this typo about a hundred times, and have finally got out of the habit of doing it. I’ll bet that is part of the issue.
Your
form_forneeds and equal sign, because it outputs HTML into your view. The loop itself does not, because it is just a loop.