I have the following code and I am not able to get it working. The error message is not coming on the top, it is just getting displayed on a different page if I dont have the rescue block commented at the bottom. Model: user.rb require "digest/sha1" class User < ActiveRecord::Base validates_presence_of :eaddress, :fname, :passwd, :pcode, :country, :day, :year, :month, :gender, :agreement validates_confirmation_of :passwd validates_uniqueness_of :eaddress validates_length_of :eaddress, :within => 6..255 validates_numericality_of :pcode end View: index.rhtml ... <table class="compbox" cellpadding="0" cellspacing="0"> <tr><td class="panelheader">Quick Register!</td></tr> <tr valign="top" align="left"> <td class="loginbg"> <%= form_tag(:controller => "login", :action => "register_user") %> <%= error_messages_for(:user) %> ... Controller: community_controller.rb def register_user # begin @user = User.new(params["user"]) @user.passwd = User.hash_password(params["user"]["passwd"]) if @user.save! redirect_to(:controller => "profile", :action => "createprofile") else render(:template => "login/index") end # rescue Exception => exc # flash[:notice] = "General error in registration = #{exc.message}" # render(:template => "login/index") # return # end end -- Posted via http://www.ruby-forum.com/.
On 7/24/06, Vinod Krishnan <vinod.krishnan@gmail.com> wrote:> > I have the following code and I am not able to get it working. The error > message is not coming on the top, it is just getting displayed on a > different page if I dont have the rescue block commented at the bottom. > > Model: user.rb > require "digest/sha1" > > class User < ActiveRecord::Base > > validates_presence_of :eaddress, :fname, :passwd, :pcode, :country, > :day, :year, :month, :gender, > :agreement > > validates_confirmation_of :passwd > validates_uniqueness_of :eaddress > validates_length_of :eaddress, :within => 6..255 > validates_numericality_of :pcode > > > end > > View: index.rhtml > ... > <table class="compbox" cellpadding="0" cellspacing="0"> > > <tr><td class="panelheader">Quick Register!</td></tr> > > <tr valign="top" align="left"> > <td class="loginbg"> > > <%= form_tag(:controller => "login", :action => "register_user") %> > <%= error_messages_for(:user) %> > ... > > Controller: community_controller.rb > def register_user > > # begin > @user = User.new(params["user"]) > @user.passwd = User.hash_password(params["user"]["passwd"])The @user.save! is the destructive form. If the user does not save an error is raised. Hence the requirement for a rescue clause. Use @user.save instead. This should then become if @user.save if @user.save!> redirect_to(:controller => "profile", :action => "createprofile") > else > render(:template => "login/index") > end > # rescue Exception => exc > # flash[:notice] = "General error in registration = #{exc.message}" > # render(:template => "login/index") > # return > # end > > end > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060724/b108bb8c/attachment.html
I have the following code and I am not able to get it working. The error message is not coming on the top, it is just getting displayed on a different page if I dont have the rescue block commented at the bottom. Model: user.rb require "digest/sha1" class User < ActiveRecord::Base validates_presence_of :eaddress, :fname, :passwd, :pcode, :country, :day, :year, :month, :gender, :agreement validates_confirmation_of :passwd validates_uniqueness_of :eaddress validates_length_of :eaddress, :within => 6..255 validates_numericality_of :pcode end View: index.rhtml ... <table class="compbox" cellpadding="0" cellspacing="0"> <tr><td class="panelheader">Quick Register!</td></tr> <tr valign="top" align="left"> <td class="loginbg"> <%= form_tag(:controller => "login", :action => "register_user") %> <%= error_messages_for(:user) %> ... Controller: community_controller.rb def register_user # begin @user = User.new(params["user"]) @user.passwd = User.hash_password(params["user"]["passwd"]) if @user.save! redirect_to(:controller => "profile", :action => "createprofile") else render(:template => "login/index") end # rescue Exception => exc # flash[:notice] = "General error in registration = #{exc.message}" # render(:template => "login/index") # return # end end
Reposting as I am not sure if this message got any replies. -------------------- I have the following code and I am not able to get it working. The error message is not coming on the top, it is just getting displayed on a different page if I dont have the rescue block commented at the bottom. Model: user.rb require "digest/sha1" class User < ActiveRecord::Base validates_presence_of :eaddress, :fname, :passwd, :pcode, :country, :day, :year, :month, :gender, :agreement validates_confirmation_of :passwd validates_uniqueness_of :eaddress validates_length_of :eaddress, :within => 6..255 validates_numericality_of :pcode end View: index.rhtml ... <table class="compbox" cellpadding="0" cellspacing="0"> <tr><td class="panelheader">Quick Register!</td></tr> <tr valign="top" align="left"> <td class="loginbg"> <%= form_tag(:controller => "login", :action => "register_user") %> <%= error_messages_for(:user) %> ... Controller: community_controller.rb def register_user # begin @user = User.new(params["user"]) @user.passwd = User.hash_password(params["user"]["passwd"]) if @user.save! redirect_to(:controller => "profile", :action => "createprofile") else render(:template => "login/index") end # rescue Exception => exc # flash[:notice] = "General error in registration = #{exc.message}" # render(:template => "login/index") # return # end end
<%= error_messages_for ''user'' %> <snip> -- rm -rf / 2>/dev/null - http://null.in "Things do not happen. Things are made to happen." - JFK
When I print out the HTML, the error_messages_for does not get converted to the div code. The rails version I am using is 1.1.2 <td> <table class="compbox" cellpadding="0" cellspacing="0"> <tr><td class="panelheader">Quick Register!</td></tr> <tr valign="top" align="left"> <td class="loginbg"> <%= form_tag(:controller => "login", :action => "register_user") %> <br/> <%= error_messages_for ''user'' %> <br/> converts to: <td> <table class="compbox" cellpadding="0" cellspacing="0"> <tr><td class="panelheader">Quick Register!</td></tr> <tr valign="top" align="left"> <td class="loginbg"> <form action="/login/register_user" method="post"> <br/> <br/> Notice the second br ---------- Forwarded message ---------- From: Vinod Krishnan <vinod.krishnan@gmail.com> Date: Jul 24, 2006 11:58 PM Subject: Re: [Rails] error_messages_for not working To: Pratik <pratiknaik@gmail.com> Hmm thanks for your help. What is Edge Rails? My rails version is 1.1.2 which I got by doing "rails -v" On 7/24/06, Vinod Krishnan <vinod.krishnan@gmail.com> wrote:> ohh, so i just need to use an older rails then? > > On 7/24/06, Pratik <pratiknaik@gmail.com> wrote: > > This is a bug in edge rails. So you''ll have to use stable release till > > it gets fixed. > > > > On 7/25/06, Vinod Krishnan <vinod.krishnan@gmail.com> wrote: > > > That was not the problem. > > > > > > On 7/24/06, Pratik <pratiknaik@gmail.com> wrote: > > > > <%= error_messages_for ''user'' %> > > > > > > > > <snip> > > > > -- > > > > rm -rf / 2>/dev/null - http://null.in > > > > > > > > "Things do not happen. Things are made to happen." - JFK > > > > _______________________________________________ > > > > Rails mailing list > > > > Rails@lists.rubyonrails.org > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > > -- > > rm -rf / 2>/dev/null - http://null.in > > > > "Things do not happen. Things are made to happen." - JFK > > >
I have the same problem - no div code and therefor no highlighted boxes. I''m also using 1.1.2. Does anyone know why ? kr Torben Vinod Krishnan wrote:> When I print out the HTML, the error_messages_for does not get > converted to the div code. The rails version I am using is 1.1.2 > > <td> > <table class="compbox" cellpadding="0" cellspacing="0"> > > <tr><td class="panelheader">Quick Register!</td></tr> > > <tr valign="top" align="left"> > <td class="loginbg"> > > <%= form_tag(:controller => "login", :action => > "register_user") %> <br/> > <%= error_messages_for ''user'' %> <br/> > converts to: > > <td> > <table class="compbox" cellpadding="0" cellspacing="0"> > > <tr><td class="panelheader">Quick Register!</td></tr> > > <tr valign="top" align="left"> > <td class="loginbg"> > > <form action="/login/register_user" method="post"> <br/> > <br/> > > Notice the second br > > ---------- Forwarded message ---------- > From: Vinod Krishnan <vinod.krishnan@gmail.com> > Date: Jul 24, 2006 11:58 PM > Subject: Re: [Rails] error_messages_for not working > To: Pratik <pratiknaik@gmail.com> > > > Hmm thanks for your help. What is Edge Rails? My rails version is > 1.1.2 which I got by doing "rails -v" > > On 7/24/06, Vinod Krishnan <vinod.krishnan@gmail.com> wrote: >> ohh, so i just need to use an older rails then? >> >> On 7/24/06, Pratik <pratiknaik@gmail.com> wrote: >> > This is a bug in edge rails. So you''ll have to use stable release till >> > it gets fixed. >> > >> > On 7/25/06, Vinod Krishnan <vinod.krishnan@gmail.com> wrote: >> > > That was not the problem. >> > > >> > > On 7/24/06, Pratik <pratiknaik@gmail.com> wrote: >> > > > <%= error_messages_for ''user'' %> >> > > > >> > > > <snip> >> > > > -- >> > > > rm -rf / 2>/dev/null - http://null.in >> > > > >> > > > "Things do not happen. Things are made to happen." - JFK >> > > > _______________________________________________ >> > > > Rails mailing list >> > > > Rails@lists.rubyonrails.org >> > > > http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > >> > > >> > >> > >> > -- >> > rm -rf / 2>/dev/null - http://null.in >> > >> > "Things do not happen. Things are made to happen." - JFK >> > >> > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >