I'm having a problem with some pesky select_tags, I can get them to show data fine on the new but when it comes to edit, they don't show up, here is the code I have at the moment. I think I need to use include?
but I don't know where to put it.
This is what I have at the moment for the new
<% @data = Code.find(:all, :conditions => "section = 'Location'") %>
<%= select_tag "candidate[code_ids][]", options_for_select(@data.map{|d| ["#{d.value}",d.id]}), :multiple => true %>
And this is for the edit
<% @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 %>
In my controller I have this which grabs all of the codes that are related to that candidate.
@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
How can I make it so I only have one select rather than having one for new and one for edit?
Long after you asked... But this is how I have been able to make a form with multi-select drop-down reload properly each time. Admittedly, this is using params and not data...
<%= type_list = EventConstants::EventType::to_array
select_tag(:event_types, options_for_select(type_list, params[:event_types]),
:multiple => true, :size => 5) %>
Since I am using mongo_mapper, I can just chain Plucky queries as so:
qry_where = qry_where.where(:event_type.in => params[:event_types]) if params[:event_types] && !params[:event_types].include?("All")
精彩评论