model error_messages_for

I have this in my form view:

<%= error_messages_for 'post' %>

I'm not using form_for, just a regular form_tag: <% form_tag :action => 'save_requirement' do %>

The error messages do not pop up, any suggestions?

Thanks!

I have this in my form view:

<%= error_messages_for 'post' %>

I'm not using form_for, just a regular form_tag: <% form_tag :action => 'save_requirement' do %>

The error messages do not pop up, any suggestions?

is @post an instance of an activerecord object with some errors?

Fred

is @post an instance of an activerecord object with some errors?

Fred

Yes,

controller:

  def new_requirement     @post = Post.new   end

  def save_requirement       @post = Post.new(params[:post])

      if @post.save         redirect_to_index("Thank you for your post!")       else         redirect_to :action => :new_requirement       end   end

Hi --

is @post an instance of an activerecord object with some errors?

Fred

Yes,

controller:

def new_requirement    @post = Post.new end

def save_requirement      @post = Post.new(params[:post])

     if @post.save        redirect_to_index("Thank you for your post!")      else        redirect_to :action => :new_requirement      end end

In the failure case, you don't want to redirect; you want to render. Redirecting triggers a completely new request cycle, with a new controller instance, and all instance variables are reset to nil. So @post will be back to being a new Post instance, which will not have any errors, so no errors will be displayed.

If you render, on the other hand, you'll just be rendering the new_requirement template with the existing @post object, which does have errors.

David

Ah! Great David!

Thanks so much, it works!