class WorkflowController < ApplicationController
  before_filter :authenticate_user!
  
  def index
    @vacancies = {}
    @candidatures = {}
    
    { vacancies: Vacancy::STATES, candidatures: Candidature::STATES }.each do |controller, states|
      states.each do |state|
        if controller == :vacancies
          eval("@#{controller}[state] = Vacancy.where(offeror_id: current_user.id, state: state).order('created_at DESC').limit(5)")
        else
          eval("@#{controller}[state] = current_user.offeror_#{controller}.where(state: state).limit(5)")
        end
      end
    end
  end
end
class WorkflowController < ApplicationController
  before_filter :authenticate_user!
  
  def index
    @vacancies = {}
    @candidatures = {}
    
    { vacancies: Vacancy::STATES, candidatures: Candidature::STATES }.each do |controller, states|
      query = 'offeror_id = :user_id'
      query += ' OR author_id = :user_id' if controller == :vacancies
      query = "(#{query}) AND state = :state"
      
      states.each do |state|
        # eval("@#{controller}[state] = current_user.offeror_#{controller}.where(state: state).limit(5)")
        vacancies = controller.to_s.classify.constantize.where(
          query, user_id: current_user.id, state: state
        ).order('created_at DESC').limit(5)
        eval("@#{controller}[state] = vacancies")
      end
    end
  end
end
Include author id in workflow vacancies filter query.
Include author id in workflow vacancies filter query.
