zoukankan      html  css  js  c++  java
  • 用RJS写的检测用户名和email是否存在

    1, Client的check url

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

    2, Controller的action

    def check_avaiable
      respond_to 
    do |format|
        format.html { redirect_to 
    '/' }
        format.js
      end
    end

    3, RJS 文件

    代码
    exist_user  = User.find_by_username(params[:username])

    if exist_user.nil? then
      page.replace_html :check_username, :partial 
    => 'check_avaiable', :locals=>{:check_value => params[:username]}
    else
      page.replace_html :check_username, :partial 
    => 'check_not_avaiable', :locals=>{:check_value => params[:username]}
    end

    exist_email 
    = User.find_by_email(params[:email])

    if exist_email.nil? then
      page.replace_html :check_email, :partial 
    => 'check_avaiable', :locals=>{:check_value => params[:email]}
    else
      page.replace_html :check_email, :partial 
    => 'check_not_avaiable', :locals=>{:check_value => params[:email]}
    end
  • 相关阅读:
    海伦公式
    简单的博弈
    Hello World 代码
    Hello world
    99999999海岛帝国后传:算法大会
    判断质数
    idea plantUML配置
    测试用例评审
    如何编写有效测试用例
    测试用例设计——场景分析法
  • 原文地址:https://www.cnblogs.com/Hacker/p/1737040.html
Copyright © 2011-2022 走看看