Error_messages_for not working

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

Quick Register!

<%= 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

On 7/24/06, Vinod K. [email protected] wrote:

validates_presence_of :eaddress, :fname, :passwd, :pcode, :country,

<%= 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!

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