안녕 저는 Ruby On Rails에서 새롭고이 문제를 발견했습니다.Ruby On Rails 드롭 - 셀렉트리스트에 숫자 대신 정수 제목이 붙은 양식
나는 4 개의 테이블과 1 개의 테이블에 3 개의 테이블이 연결되어 있습니다.
- Sportcategories -
- 클럽 각 스포츠의 이름 - - 각 카테고리
- 스포츠의 이름을 각 클럽의 이름
- 결과, t.integer는 "sportcategory_id는" t.integer는 "sport_id" t.integer "club_id"
결과의 각 입력란에 대해 text_field를 사용하여 간단한 수정 양식을 작성했습니다. 그러나 숫자 대신 정수의 이름을 어떻게 얻을 수 있습니까?
<%= form_for(@result) do |f| %>
#if...
#..
#end
<div class="field">
<%= f.label :sportcategory_id%><br />
<%= f.text_field :sportcategory_id%>
</div>
<div class="field">
<%= f.label :sport_id %><br />
<%= f.text_field :sport_id %>
</div>
<div class="field">
<%= f.label :club_id %><br />
<%= f.text_field :club_id %>
</div>
<div class="field">
<%= f.label :result %><br />
<%= f.text_field :result %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
나는 스포츠 캣, 스포츠 및 클럽에 많은 결과가 있으며 그 결과가 모두에게 포함되도록 만들었습니다.
이 질문 하나에 대답 할 수
def edit
@result = Price.find(params[:id])
end
def update
@price = Price.find(params[:id])
respond_to do |format|
if @price.update_attributes(params[:price])
format.html { redirect_to(@price, :notice => 'Price was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @price.errors, :status => :unprocessable_entity }
end
end
end
그리고이 질문을 편집 & 업데이트의 결과를 내 컨트롤러 파일입니다,하지만 난 가능한 모든에서 드롭 다운 목록에서 선택 할 수있게하려면 카테고리, 스포츠 및 클럽을 실제 이름으로 변경 한 다음 업데이트 할 때 올바른 ID를 전달하십시오.
대단히 감사합니다! 나는이 언어를 아주 좋아합니다 ... – Philip