I’ve created my user model which validates against the database for a
proper user/pass combination. I’ve set validation options to ensure
that
both a user and password are entered.
I would like to check via an ajax call whether or not the username is
taken. I haven’t been able to find a tutorial covering this topic. Do
any of you know of one?
Additionally you can use the link_to_remote options. eg :loading,
:complete
etc
Then in your controller you have a method
def check_user_name @user = User.find_by_name( params[:user][:name] ) || User.new
if @user.new_record?
render :inline => “Div contents to indicate that the name is
available. This will go in the div” and return
else
render :inline => “Div contents to indicate that it’s taken”
end
end
I’ve created my user model which validates against the database for a
proper user/pass combination. I’ve set validation options to ensure that
both a user and password are entered.
I would like to check via an ajax call whether or not the username is
taken. I haven’t been able to find a tutorial covering this topic. Do
any of you know of one?
[…]
What about something like the following (not tested):
And in your controller (ie. ‘users_controller.rb’):
def check_for_availability
if User.find_by_username(params[:username]).empty?
render :inline => ’ Oh yeah! Good choice dude!’
else
return :inline => ’ Please, choose another username ’
end
end
Cheers,
Marco
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.