우리는이 같은 모델이있는 경우 :
create_table "doctors", force: true do |t|
t.string "name"
t.string "last_name"
t.datetime "created_at"
t.datetime "updated_at"
end
class Doctor < ActiveRecord::Base
has_many :appointments
has_many :users, :through => :appointments
def full_name
"#{name} #{last_name}"
end
end
Home
컨트롤러 :
class StaticController < ApplicationController
def home
@doctors = Doctor.all
end
end
을
우리는이 내부 Home
보기 같은 드롭 다운 메뉴를 생성 할 수 있습니다
<div>
<p>Pick a doctor</p>
<%= collection_select(:doctor, :id, @doctors, :id, :full_name) %>
</div>
그리고 사용자 후
드롭 다운 메뉴에서 다른 값을 선택하고, 어떤 조치가 실행됩니다 :
$("#doctor_id").change(function() {
var selectedVal = $(this).val();
// Do something depending on selected value
});
그거야 그 :)