Error_message_for not working

hi all,

I try to get error_message_for to get to work on my dorm. No luck…

For some reason the view doesn’t show me the error message when I for
example leave out the first_name

Some has a clue what I’m doing wrong?

Thanks,
Stijn

I use a helperform to create a new user:

New user

<%= error_messages_for 'user' %> <%= form_tag new_user_path %> first_name: <%= text_field('user', 'first_name') %>
last_name: <%= text_field('user', 'last_name') %>
email: <%= text_field('user', 'email') %>
<%= end_form_tag %>

the controller
def new
@user = User.new(params[:user])
if @user.save
flash[:notice] = “Nieuwe gebruiker aangemaakt”
end
redirect_to :back
end

the model
class User < ActiveRecord::Base
has_and_belongs_to_many :nodes
has_many :posts
validates_presence_of :first_name, :last_name
end

Apparently the problem is caused by the redirect_to :back . I need to
use render to preserve the errors.

The problem is that I call the new method in my partial, used in
different views. I thus need to redirect back. Can I use render to
send me back to the previous page?
Thanks,
Stijn

yep, i want to know that too.
how use error_message_for on redirect_to action ?
who’s know that?
i know use flash only:

def new
@user = User.new(params[:user])
if @user.save
flash[:notice] = “Nieuwe gebruiker aangemaakt”
else
flash[:error] = @user.errors.each {|field, msg| error << msg +

’ }
end
redirect_to :back
end