rails 에서 association 을 사용 하여 select 드 롭 다운 상 자 를 만 드 는 작은 기술
3191 단어 selectRailsblankassociatio
<%= f.association :match_subject,collection: MatchSubject.all, include_blank: false ,:input_html => { :class => 'span200 chzn-select' , :id => "match_subject_select_div"}, :label => MatchInfo.human_attribute_name(:subject_id), label_html: { class: 'input_label span200' }, :label_method => :display_code_and_name , :value_method => :id %>
그 중:matchsubject 는 model 에서 정의 하 는 belongsto 의 이름 에 대응
class MatchInfo < ActiveRecord::Base
belongs_to :user , :foreign_key => :user_id ,:primary_key => :id
belongs_to :match_subject ,:foreign_key => :subject_id ,:primary_key => :id
validates :subject_id, presence: true
end
:label_method => :display_code_and_name 은 메 인 테이블 에 정 의 된 디 스 플레이 방법 입 니 다.
class MatchSubject < ActiveRecord::Base
def display_code_and_name
"#{code} - #{name}"
end
end
드 롭 다운 상자 목록 읽 기 전용
match_subject_select_div = $("#match_subject_select_div").select2 (
placeholder: " ",
width: "200px",
theme: "classic"
)
match_subject_select_div.select2("enable", false)
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
SQL Day 1_DB, My SQL파이썬 과정이 끝나고 SQL과정 첫 날이었다. 파이썬보다 환경설정에서 까다로웠지만 MySQL로 어떤 활용을 할 수 있는지 감은 잡힌 거 같다. 파이썬의 BeatifulSoup과 Selenium으로 크롤링을 해온 자료...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.