반복되는 응용 프로그램 형태로, I했습니다 다중 선택에 대한 다음 코드를레일 collection_select 필드 항목 내 레일에서
<div class="field">
<%= f.label :frameworks %><br />
<%= f.collection_select :framework_ids, Framework.all, :id, :name, {}, {:multiple => true} %>
</div>
그것은 창조에서 잘 작동하고 올바르게 편집에 previowsly 선택 프레임 워크를 보여줍니다 전망.
하지만 업데이트 된 다른 필드를 제출하면 데이터베이스의 프레임 워크 항목이 반복됩니다.
예를 들어 데이터베이스 "framework1", "frameworks2", "framework1", "frameworks2"를 업데이트 한 후 "framework1", "frameworks2"를 선택한 경우 한 번 더 업데이트하면 다음과 같이됩니다. "프레임 워크 1", "프레임 워크 2", "프레임 워크 1", "프레임 워크 2", "프레임 워크 1", "프레임 워크 2"
그래서 그것을 방지하려면 어떻게해야합니까?
편집 : 컨트롤러는 여기에 있습니다 : 내가 할로 numImages :
@component = Component.find(params[:id])
respond_to do |format|
if @component.update_attributes(params[:component])
@component.update_attribute(:numImages, @component.assets.size)
@component.save
format.html { redirect_to @component, notice: 'Component was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @component.errors, status: :unprocessable_entity }
end
end
끝
그런데, 업데이트 할 올바른?
는 컨트롤러 측 코드를 제공하시기 바랍니다, 문제는 내가 컨트롤러 부분을 추가 한 뷰 페이지 – Salil
에 존재하지 존재한다. – user1573607