0
일부 성가신 select_tags에 문제가 있습니다. 데이터를 새로 표시하도록 설정할 수 있지만 편집 할 때 표시되지 않습니다. 여기에 코드가 있습니다. 순간. 나는 include?
을 사용할 필요가 있다고 생각하지만 어디에 넣어야할지 모르겠다. select_tag multiple and partials
이
내가 새로운<% @data = Code.find(:all, :conditions => "section = 'Location'") %>
<%= select_tag "candidate[code_ids][]", options_for_select(@data.map{|d| ["#{d.value}",d.id]}), :multiple => true %>
의 순간이 그리고 이것은 관련있는 코드를 모두 잡고 나는이를 내 컨트롤러에서 편집
<% @data = Code.find(:all, :conditions => "section = 'Location'") %>
<%= select_tag "candidate[code_ids][]", options_for_select(@data.map{|d| ["#{d.value}",d.id]},@found), :multiple => true %>
위한 것입니다 그 후보자에게.
@results = Candidate.all :joins =>
"LEFT JOIN candidates_codes ON candidates.id = candidates_codes.candidate_id",
:conditions => ["candidates.id = ?", params[:id]],
:select => "candidates_codes.code_id"
#create an array of the candidates selected codes
@found = []
for c in @results
@found.push(c.code_id.to_i)
end
어떻게 새 항목 하나를 편집하는 대신 하나만 선택할 수 있습니까?
: 인정 하듯이,이
내가 mongo_mapper을 사용하고 있기 때문에, 나는 그렇게으로 잘난 쿼리를 단지를 체인 수 있습니다 ... PARAMS이 아닌 데이터를 사용 서로 관련성이 있습니까? 첫 번째 스 니펫은'@ results' 또는'@ found'를 사용하지 않습니다. –
수정 사항을 추가했습니다. 감사합니다. John –