Validation error_messages_for problem

I am having trouble getting error_messages_for to work.

My controller(relevant parts) looks like

def configure
@account = session[:account]
@user = User.new
end

def add_new_user_to_account
@user = User.new(params[:user])
if @user.valid?
session[:account].users << @user
end
redirect_to :action=> ‘configure’
end
end

and my view configure.rhtml

<%= error_messages_for ‘user’ %>
<%=start_form_tag :action =>‘add_new_user_to_account’%>
First Name: <%=text_field ‘user’, ‘first_name’%>

Last Name: <%=text_field ‘user’, ‘last_name’%>

Username: <%=text_field ‘user’, ‘username’%>

Password: <%=password_field ‘user’, ‘password’%>

Email: <%=text_field ‘user’, ‘email’%>

Admin?<%=check_box(“user”, “admin”)%>

<%=submit_tag%>
<%=end_form_tag%>

If I enter data that does not validate the record is not saved (which is
good) but error_messages_for ‘user’ doesn’t show any errors(which is
bad). If I go into the console and make an invalid user I am shown the
correct errors in @user.error so my validations are working on the
model, they just aren’t making their way through the controller to the
view.

Any ideas?

Thank you,
Matthew M.
blog.mattmargolis.net

On Tuesday, June 20, 2006, at 1:58 PM, Matthew M. wrote:

@user = User.new(params[:user])
<%=start_form_tag :action =>‘add_new_user_to_account’%>
good) but error_messages_for ‘user’ doesn’t show any errors(which is


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

I’ve been having a similar problem lately, and I suspect that the
‘redirect_to’ is swallowing up the instance variables.

‘redirect_to’ will essentially make another call to the indicated
action. Unless that action manually pulls the instance variables from
the post data and sends them along to it’s own template, all that data
is lost.

As a test, try this at the beginning of the ‘configure’ action…

@user = User.new(params[:user]) if params[:user]

_Kevin

Kevin O. wrote:

Matthew M.
‘redirect_to’ will essentially make another call to the indicated

Yes, switching to render :action => ‘configure’ fixed the problem.

Thank you,
Matthew M.
blog.mattmargolis.net

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs