How to retain the values of textboxes if validation is there

Hi all,

I have applied a validation in user model for the uniqueness of login
name. i.e.
validates_uniqueness_of :login, :message => “username already exists”.
When i click on submit button and the login already exists then message
is displayed:
1 error prohibited this user from being saved
There were problems with the following fields:
* Login username already exists

but the values in the textboxes can not be retained.
I want this validation and the values in the textboxes to be retained.

Any help would be greatly appreciated.

Thanks,
Ruchita.

you should work on @user in your controller, then
text_field(:user, :login) will be full fill with @user.login

On Dec 24, 1:40 pm, Ruchita S. [email protected]

Are you trying the scaffold generator? We may need more information to
help you with this. Probably the best place to ask this kind of help
is to login into the irc freenode.

On Dec 24, 5:40 pm, Ruchita S. [email protected]

blj wrote:

Are you trying the scaffold generator? We may need more information to
help you with this. Probably the best place to ask this kind of help
is to login into the irc freenode.

On Dec 24, 5:40 pm, Ruchita S. [email protected]

Hi all,

Actually I am implementing a registration form. In that I have applied a
validation in user model to validate the uniqueness of login.
validates_uniqueness_of :login, :message => “login already exists”
If the user login already exits then it displays the message login
already exists
but at the same time i want to retain the values in other fields like
first name, last name and so on.

Any help would be greatly appreciated.

Thanks,
Ruchita.

Actually the best place to ask is right here.

Could you show us the code you’re using in your create action Ruchita?

On Dec 27, 2007 4:14 PM, Ruchita S.
[email protected]
wrote:

Actually I am implementing a registration form. In that I have applied a
Thanks,
Ruchita.

Posted via http://www.ruby-forum.com/.


Ryan B.

Feel free to add me to MSN and/or GTalk as this email.

Try using the ‘form_for’ tag in the view file.

Ryan B. wrote:

Actually the best place to ask is right here.

Could you show us the code you’re using in your create action Ruchita?

On Dec 27, 2007 4:14 PM, Ruchita S.
[email protected]
wrote:

Actually I am implementing a registration form. In that I have applied a
Thanks,
Ruchita.

Posted via http://www.ruby-forum.com/.


Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.

The code for signup is:
def signup
@rightpanels = Rightpanel.find(:all, :limit => 2, :order => ‘rand()’)
@countries = Country.find :all
@user = User.new
@user = User.new(params[:user])
salt=‘hex123folkstory’
@user.password=Digest::SHA1.hexdigest(params[:user][:password] +
salt)
if @user.save
flash[:notice] = ‘You will recieve a mail on your account with login
info and link, once the admin activates your account’
redirect_to :controller => ‘store’, :action => ‘login’
else
flash[:notice] = ‘This Login already Exist.Try Again!’
render :action => ‘sign_up’ , :layout => true, :id => @user.id

redirect_to :action => ‘sign_up’, :controller => ‘store’

end

end

User model is:
validates_uniqueness_of :login, :message => “username already exists”

This is the code of controller and model.

Thanks,
Ruchita.

Just render :action => “signup” should do the trick (without :layout and
:id), and the signup and the method where it actually puts a new record
into
the database should be two seperate actions. Currently in your code
it’ll
try to create a new user even when you’re viewing the page.

On Dec 27, 2007 4:46 PM, Ruchita S.
[email protected]
wrote:

Actually I am implementing a registration form. In that I have applied

salt=‘hex123folkstory’
end


Posted via http://www.ruby-forum.com/.


Ryan B.

Feel free to add me to MSN and/or GTalk as this email.

Ok… shall i split the code for signup and create?

Yes, that’s what you should do.

On Dec 27, 2007 4:57 PM, Ruchita S.
[email protected]
wrote:

Ok… shall i split the code for signup and create?

Posted via http://www.ruby-forum.com/.


Ryan B.

Feel free to add me to MSN and/or GTalk as this email.

Ryan B. wrote:

Yes, that’s what you should do.

On Dec 27, 2007 4:57 PM, Ruchita S.
[email protected]
wrote:

Ok… shall i split the code for signup and create?

Posted via http://www.ruby-forum.com/.

Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.
I have split the code for signup and create even then it’s not working.

def signup
@rightpanels = Rightpanel.find(:all, :limit => 2, :order =>
‘rand()’)
@countries = Country.find :all
@user = User.new
end

def create
@rightpanels = Rightpanel.find(:all, :limit => 2, :order =>
‘rand()’)
@countries = Country.find :all
@user = User.new(params[:user])
salt=‘hex123folkstory’
@user.password=Digest::SHA1.hexdigest(params[:user][:password] +
salt)
if @user.save
flash[:notice] = ‘You will recieve a mail on your account with login
info and link, once the admin activates your account’
redirect_to :controller => ‘store’, :action => ‘login’
else
flash[:notice] = ‘This Login already Exist.Try Again!’
render :action => ‘sign_up’
end
end

Please tell me what needs to be done?

Thanks,
Ruchita.

Can you please show your ‘sign_up.rhtml’ view file also?

If i user rails tag then it is difficult to put javascript validations.
That is the reason I have done it with html tags.

Karthi kn wrote:

Can you please show your ‘sign_up.rhtml’ view file also?

It is a very big file.
Let me show you only two fields from that file with form tag.
Javascript validations are also there.

Please fill this form for registeration
Note: Fields marked with * are mandatory
  
*Login
*Password
*Confirm Password

Ruchita S. wrote:

If i user rails tag then it is difficult to put javascript validations.
That is the reason I have done it with html tags.

Ok. Did you try changing the id of the input text field?

Ryan B. wrote:

Yes, please use the text_field tag helpers. It’s not difficult to put
javascript validations on there, as you can specify any attribute you
would
normally specify on the tag as another option in the tag.

<%= text_field “user”, “login”, { :onclick => “alert(‘test’)” } %>

You’re also typing value="" in your text fields, so they can’t have any
values! The text_field helper will automatically fill in these values
for
you.

Yes. ’ value="" ’ should not be there in the input tag.

Yes, please use the text_field tag helpers. It’s not difficult to put
javascript validations on there, as you can specify any attribute you
would
normally specify on the tag as another option in the tag.

<%= text_field “user”, “login”, { :onclick => “alert(‘test’)” } %>

You’re also typing value=“” in your text fields, so they can’t have any
values! The text_field helper will automatically fill in these values
for
you.


Ryan B.

Feel free to add me to MSN and/or GTalk as this email.

Karthi kn wrote:

Ryan B. wrote:

Yes, please use the text_field tag helpers. It’s not difficult to put
javascript validations on there, as you can specify any attribute you
would
normally specify on the tag as another option in the tag.

<%= text_field “user”, “login”, { :onclick => “alert(‘test’)” } %>

You’re also typing value="" in your text fields, so they can’t have any
values! The text_field helper will automatically fill in these values
for
you.

Yes. ’ value="" ’ should not be there in the input tag.

I have checked it by changing the id as user_login and by deleting the
value="".
Its not working.

Karthi kn wrote:

I have checked it by changing the id as user_login and by deleting the
value="".
Its not working.

Is it throwing any exception or is the value not retained in UI?

Not throwing any exception… but it is not retaining the values in
the textfields.

I have checked it by changing the id as user_login and by deleting the
value="".
Its not working.

Is it throwing any exception or is the value not retained in UI?