Forum: Ruby on Rails errors not showing

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
thomas.tmp (Guest)
on 2005-11-23 00:24
(Received via mailing list)
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) %>
This topic is locked and can not be replied to.