Hello,
I hope someone can help me with a problem.
Given the following code:
class User < ActiveRecord::Base
validates_uniqueness_of :username, :message => "Username is
taken"
validates_presence_of :username
validates_presence_of :password
end
<%= error_messages_for ''user'' %>
<%= form_tag %>
<table>
<tr>
<td>Username:</td>
<td><%= text_field("user", "username")
%></td>
<td>I WANT TO DISPLAY USERNAME ERRORS HERE</td>
</tr>
<tr>
<td>Password:</td>
<td><%= password_field("user", "password")
%></td>
<td>I WANT TO DISPLAY PASSWORD ERRORS HERE</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value=" ADD USER "
/></td>
</tr>
</table>
<%= end_form_tag %>
I don''t want to display all of the errors in one block using
<%error_messages_for ''user'' %>
How can I display error messages for specific form fields individually
as indicated in the HTML above?
Thank you so much for your help.
Chris
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On May 6, 2007, at 8:21 PM, Chris wrote:> <tr> > <td>Username:</td> > <td><%= text_field("user", "username") %></td> > <td>I WANT TO DISPLAY USERNAME ERRORS HERE</td>The starting point is @user.errors.on(:username). -- fxn --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for your help. I have now solved the problem.
For anyone else experiencing the same problem, here is the code:
<%= form_tag :action => ''do_something'' %>
<table>
<tr>
<td>Username:</td>
<td><%= text_field("user", "username")
%></td>
<td><%= error_message_on("user", "username")
%></td>
</tr>
<tr>
<td>Password:</td>
<td><%= password_field("user", "password")
%></td>
<td><%= error_message_on("user", "password")
%></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value=" ADD USER "
/></td>
</tr>
</table>
<%= end_form_tag %>
class MyController < ApplicationController
def do_something
@user = User.new(@params[''user''])
if @user.save
# User was saved
else
# User was not saved so redisplay the form
end
end
end
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---