惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks
博客园 - 聂微东
Microsoft Azure Blog
Microsoft Azure Blog
量子位
T
Tailwind CSS Blog
Vercel News
Vercel News
I
InfoQ
Stack Overflow Blog
Stack Overflow Blog
U
Unit 42
Engineering at Meta
Engineering at Meta
L
LangChain Blog
大猫的无限游戏
大猫的无限游戏
D
Docker
博客园_首页
P
Proofpoint News Feed
月光博客
月光博客
T
The Blog of Author Tim Ferriss
MyScale Blog
MyScale Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Martin Fowler
Martin Fowler
腾讯CDC
N
Netflix TechBlog - Medium
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - James

Send-only Mail Server with Exim on Ubuntu 10.04 LTS Change hostname on Ubuntu without reboot 51IT最全的自动化测试工具QTP资料 QTP如何启动应用程序(转) - James - 博客园 找出用户表中有重复密码的用户 如何改变Linux Kennel中的shmmax参数 如何在C语言中使用constructor和destructor,gcc环境 如何在Ubuntu上update gem for ruby 1.9.1的版本 google疯了 - James - 博客园 碰巧遇到一些智力面试题,解答一下 避免在电脑上浪费时间的好办法 如何在Postgresql中产生自己的集合function 用RJS写的检测用户名和email是否存在 MSN Messager密码 - James - 博客园 重新开始Blog生活 准备用C#写一个Blog的客户端,大家看看功能缺哪些,哪些不需要? PInvoke 白话文 Apache 2 + PHP Windows安装指南(官方版本) .Text Blog .95中一个Unicode的bug - James
ajax check username available in rails
James · 2010-05-17 · via 博客园 - James

1, Client

<%=link_to_remote 'Check Availability',
   :submit   => "signupForm",
   :url 
=> {:controller => 'users', :action => 'check_username_avaiable' },
   :update => 'check_username',
   :html => {:class => 'smallText'} %>

 注意这里的submit 是Form的ID, update是ajax回来以后要update的DOM的ID 

2, server

  def check_username_avaiable
    exist_user 
= User.find_by_username(params[:username])
    exist_user 
= 'yes' if params[:username] == 'demo'
    
if exist_user.nil? then
      render :partial
=>'username_avaiable', :locals => {:username => params[:username]}
    
else
      render :partial
=>'username_not_avaiable', :locals => {:username => params[:username]}
    end
  end