I'm using counter_culture to create survey applications the problem is each time I add citizen the count columns is not automatically update I have to go to console and run Citizen.counter_culture_fix_counts below is my model and controller for reference I'm using rails 4 and nested_attributes
thank you for help
model
class Familycard < ActiveRecord::Base
has_many :citizens , :dependent => :destroy
accepts_nested_attributes_for :citizens, :allow_destroy => :true
end
class Citizen < ActiveRecord::Base
belongs_to :familycard
counter_culture :familycard,
:column_name => Proc.new { |model| "#{model.sex}_count"},
:column_names => {
["citizens.sex = ? ", 'male'] => 'males_count',
["citizens.sex = ? ", 'female'] => 'females_count'
}
counter_culture :familycard
counter_culture :familycard,
:column_name => Proc.new { |model| "#{model.job}_count"},
:column_names => {
["citizens.job = ? ", 'Entrepreneur'] => 'Entrepreneurs_count',
["citizens.job = ? ", 'House wife'] => 'housewifes_count',
["citizens.job = ? ", 'Student'] => 'students_count',
["citizens.job = ? ", 'Veteran'] => 'veterans_count',
}
end
controller
class FamilycardController < ApplicationController
def new
@familycard = Familycard.new(:citizens => [Citizen.new])
end
def create
@familycard = Familycard.new(familycard_params)
if @familycard.save
flash[:success] = "Data Saved"
redirect_to familycards_path
else
render 'familycards/familycard_form'
end
end