Ruby on Rails - f.error_messages not showing up -


i've read many posts issue never got work.

my model looks this:

class announcement < activerecord::base     validates_presence_of :title, :description end 

my controller's create method(only relevant part) looks this:

def create     respond_to |format|       if @announcement.save         flash[:notice] = 'announcement created.'         format.html { redirect_to(@announcement) }         format.xml  { render :xml => @announcement, :status => :created, :location => @announcement }       else         @announcement = announcement.new         @provinces = province.all         @types = announcementtype.all         @categories = tag.find_by_sql 'select * tags  parent_id=0 order name asc'         @subcategories= ''         format.html { render :action => "new" } #new_announcement_path         format.xml  { render :xml => @announcement.errors, :status => :unprocessable_entity }       end     end   end 

my form looks this:

<% form_for(@announcement) |f| %>     <%= error_messages_for 'announcement' %> <!--i've treid f.error_messages--> ... 

what doing wrong?

you killing error messages creating new announcement in else statement.

@announcement = announcement.new # should removed 

when call @announcement.save store errors in @announcement.errors. calling @announcement = announcement.new after going clean slate. no errors ever displayed.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -