Hi, having trouble validating my form:
_form.html.erb:
<% form_remote_for :user, @user, :url => { :action =>
"create" } do
|f| %>
<table class="table">
<tr>
<td colspan="2" class="center"><div
id="notice"><br /></div> </td>
</tr>
<tr>
<td class="text">Email:</td>
<td><%= f.text_field :email %></td>
</tr>
<tr>
<td class="text">Password:</td>
<td><%= f.text_field :password %></td>
</tr>
<tr>
<td></td>
<td align="right">
<%= submit_tag "Add user" %>
</td>
</tr>
</table>
<% end %>
controller:
def create
@user = User.new(params[:user])
if @user.save
if(request.xhr?)
render :update do |rjs|
flash[:notice] ="<font
class=''notice-obj''>" + @user.email +
"</font><font class=''notice-pos''> was added
successfully!</font>"
rjs.replace_html "notice", :partial =>
''notice''
rjs.visual_effect(:highlight, "notice", :startcolor =>
"#D6D6D6", :endcolor => "#ffffff", :duration => 2)
end
else
redirect_to_index and return
end
end
end
On the surface, it seems that if a user enters invalid info into the
fields, it doesn''t make it to the redirect_to_index at all. In fact,
when I put a flash[:notice] into the else and submit invalid info, it
doesn''t make it. That''s problem #1.
I guess problem #2 follows #1. Where would I put <%= error_messages_for
''user'' %>, if that''s the right way to do it,
firstly.
Thanks!
--
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 the surface, it seems that if a user enters invalid info into the > fields, it doesn''t make it to the redirect_to_index at all. In fact, > when I put a flash[:notice] into the else and submit invalid info, it > doesn''t make it. That''s problem #1.Have you read through your code? cutting out the fluff it does if @user.save ... end i.e. nothing happens if the user isn''t valid. Looks like you flipped the request.xhr? test with the user validity one> > I guess problem #2 follows #1. Where would I put <%= error_messages_for > ''user'' %>, if that''s the right way to do it, firstly. >In your notice partial. Fred> Thanks! > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
def create
@user = User.new(params[:user])
if @user.save
if(request.xhr?)
render :update do |rjs|
flash[:notice] ="<font
class=''notice-obj''>" + @user.email +
"</font><font class=''notice-pos''> was added
successfully!</font>"
rjs.replace_html "notice", :partial =>
''notice''
rjs.visual_effect(:highlight, "notice", :startcolor =>
"#D6D6D6", :endcolor => "#ffffff", :duration => 2)
end
else
redirect_to_index and return
end
else
if(request.xhr?)
render :update do |rjs|
rjs.replace_html "notice", :partial =>
''notice'', :object =>
@user
#rjs.visual_effect(:highlight, "notice", :startcolor =>
"#FF8888", :endcolor => "#ffffff", :duration => 5)
end
end
end
end
partial:
<%= flash[:notice] if flash[:notice] %>
<%= @user.errors %>
I get # for errors ?
--
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
-~----------~----~----~----~------~----~------~--~---
> partial: > <%= flash[:notice] if flash[:notice] %> > <%= @user.errors %> > > I get # for errors ?You can''t just dump a ruby object into your html like that (apart from anything else the default string representation on an object has <> in it, which confuses browsers. That''s what error_messages_for is for (or build your own replacement) Fred --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---