Commit aba89a34 authored by Pedro Henrique's avatar Pedro Henrique
Browse files

Fix association between service type and service place when updating service place


Signed-off-by: Pedro Henrique's avatarPedro Henrique! <pha14@inf.ufpr.br>
parent df590d97
......@@ -25,6 +25,7 @@ class ServicePlacesController < ApplicationController
# GET /service_places/1.json
def show
@service_place = ServicePlace.find(params[:id])
@service_types_actives = ServiceTypeServicePlace.where(service_place_id: @service_place.id, active: true)
@link = "Locais de Atendimento"
@link2 = @service_place.name
......@@ -53,6 +54,7 @@ class ServicePlacesController < ApplicationController
@link = "Locais de Atendimento"
@link2 = "Alterar Local de Atendimento"
@service_types = ServiceType.active.joins(:sector).where(:sectors => {:city_hall_id => @service_place.city_hall_id})
@service_types_actives = ServiceTypeServicePlace.where(service_place_id: @service_place.id, active: true)
end
# POST /service_places
......@@ -133,9 +135,9 @@ class ServicePlacesController < ApplicationController
@service_place.service_types = ServiceType.where(:id => params[:service_place][:service_type_ids])
end
@service_place.service_types.where(:id => tmp).update_all(active: false)
@service_place.service_types.where.not(:id => tmp).update_all(active: true)
ServiceTypeServicePlace.where(service_place_id: @service_place.id).update_all(active:true)
ServiceTypeServicePlace.where(service_place_id: @service_place.id, service_type_id: tmp).update_all(active: false)
tmp = @service_place.service_types.all.pluck(:id)
params[:service_place][:service_type_ids] = tmp
respond_to do |format|
......
......@@ -103,10 +103,12 @@
<div id="checkbox-area" class="checkbox_area">
<% else %>
<div class="checkbox_area">
<% for tta in @service_types %>
<%= check_box_tag "service_place[service_type_ids][]", tta.id, @service_place.service_types.include?(tta) && tta.active, id: "service_#{tta.id}" %>
<%= label_tag "service_#{tta.id}", tta.description %><br />
<% end %>
<% if !@service_types.nil? %>
<% for tta in @service_types %>
<%= check_box_tag "service_place[service_type_ids][]", tta.id, @service_types_actives.any? {|x| x.service_type_id == tta.id }, id: "service_#{tta.id}" %>
<%= label_tag "service_#{tta.id}", tta.description %><br />
<% end %>
<% end %>
<% end %>
</div>
</div>
......
......@@ -80,7 +80,7 @@
<b>Serviços: </b>
<ul>
<% @service_place.service_types.each do |tta| %>
<% if tta.active %>
<% if @service_types_actives.any? {|x| x.service_type_id == tta.id } %>
<li><%= link_to "#{tta.description}", tta %></li>
<% end %>
<% end %>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment