ruby-on-rails
  • select
  • partial-views
  • 2010-07-26 2 views 0 likes 
    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 
    

    어떻게 새 항목 하나를 편집하는 대신 하나만 선택할 수 있습니까?

    +0

    : 인정 하듯이,이

    <%= type_list = EventConstants::EventType::to_array select_tag(:event_types, options_for_select(type_list, params[:event_types]), :multiple => true, :size => 5) %> 

    내가 mongo_mapper을 사용하고 있기 때문에, 나는 그렇게으로 잘난 쿼리를 단지를 체인 수 있습니다 ... PARAMS이 아닌 데이터를 사용 서로 관련성이 있습니까? 첫 번째 스 니펫은'@ results' 또는'@ found'를 사용하지 않습니다. –

    +0

    수정 사항을 추가했습니다. 감사합니다. John –

    답변

    0

    당신이 물어 본 후에도 오랫동안 ... 그러나 이것이 내가 매번 다중 선택 드롭 다운 리로드로 양식을 만들 수 있었던 방법입니다. 당신은 코드의 두 조각을했습니다 어떻게

    qry_where = qry_where.where(:event_type.in => params[:event_types]) if params[:event_types] && !params[:event_types].include?("All") 
    
    관련 문제