Upgrade to Pro — share decks privately, control downloads, hide ads and more …

validationについて

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for ryonext ryonext
December 16, 2015

 validationについて

Avatar for ryonext

ryonext

December 16, 2015
Tweet

More Decks by ryonext

Other Decks in Programming

Transcript

  1. class CreateUsers < ActiveRecord::Migration def change create_table :users do |t|

    t.string :name, limit: 20, null: false t.string :password t.timestamps null: false end end end %#ʹMJNJUͱOPUOVMM੍໿Λֻ͚ Δʢ3BJMTͷNJHSBUJPOͰ΍Δྫʣ
  2. +4͔ΒݺͿ ʢલεϥΠυ  ͷεςοϓ 4 $ -> 5 $("#username").keyup(-> 6

    $.get( 7 "/accounts/exists", 8 { username: $('#username').val() }, 9 (data) -> 10 if data.result 11 $("#account-result").html("<div class='glyphicon glyphicon-remove text-danger'>͜ͷϢʔβ໊͸࢖ΘΕ͍ͯ·͢</div>") 12 $("#submit-button").prop("disabled", true) 13 else 14 $("#account-result").html("<div class='glyphicon glyphicon-ok text-success'>͜ͷϢʔβ໊͸࢖༻ՄೳͰ͢</div>") 15 $("#submit-button").prop("disabled", false) 16 ) 17 ) 18 w $P⒎FF4DSJQUͰ͢ w ࣮ࡍʹLFZVQͰ΍Δͱ௨৴ස౓ଟ͗͢ΔͷͰEFCPVDF͢ΔQMVHJOͳͲ࢖͍·͠ΐ͏ w ྫ͸K2VFSZͰ͕͢ɺԿΒ͔ͷϑϨʔϜϫʔΫΛ࢖͏ͷ΋ΦεεϝͰ͢
  3. ֬ೝ༻"1*࡞Δ ʢdͷεςοϓ Rails.application.routes.draw do resources :accounts do collection do get

    "exists", to: "accounts#exist" end end end class AccountsController < ApplicationController def exist if Account.exists?(username: params[:username]) render json: { result: true }.to_json else render json: { result: false }.to_json end end end