Errors not showing


#1

Hello,

I’m facing a strange problem :
1/ I have a model that do not validate
2/ I add an error (errors.add)
3/ I try to display the error (error_messages_for), but it does not
display

error_messages_for returns nil, and I’ve checked that my model do not
validate (with the logger).

So what am I doing wrong?
Your help will be much appreciated!

You’ll find my code below.

Thanks,
Thomas B…

— my MODEL :
class Picture < ActiveRecord::Base
validate :check_size

def check_size
errors.add(:picture,‘Taille = 0’) if @temp_file.size == 0
logger.error(‘check_size’)
end
end

— my CONTROLLER :
class PicturesController < ApplicationController
def new
logger.error("–new–")
@categories = Category.find(:all,:include => ‘keywords’)
@picture = Picture.new
end

def create
@picture = Picture.new(@params[:picture])
if @picture.save
flash[:notice] = “La photo a bien été créée.”
redirect_to :controller => ‘search’
else
logger.error(“i wont save”)
redirect_to :action => ‘new’
end
end
end

— my VIEW with :
<%= error_messages_for(:picture) %>