Consul: NoMethodError in Officing::ResidenceController#new

Created on 11 Sep 2017  路  5Comments  路  Source: consul/consul

Dicho error se encuentra en la ruta /officing/residence/new, a la que se accede desde Admin > Presidentes de mesa > Validar documento y votar.

El error dice lo siguiente:

undefined method `officer_assignments' for nil:NilClass

def load_officer_assignment
      @officer_assignments = current_user.poll_officer.
                               officer_assignments.
                               voting_days.
                               where(date: Date.current)
    end

app/controllers/officing/residence_controller.rb:27:in `load_officer_assignment'

Most helpful comment

I'll take this one.

All 5 comments

Hi @periflo90! Thank you for reporting this issue. We will take care of it as soon as possible, meanwhile stay tuned here :)

--

Hola @periflo90! Muchas gracias por reportar este error. Lo resolveremos en la mayor brevedad posible, mientras tanto puedes seguir el estado del issue aqu铆 :)

I'll take this one.

While trying to locate the faulty behavior, I stumbled upon this:

2.3.2 :001 > a = User.find(1)
  User Load (2.1ms)  SELECT  "users".* FROM "users" WHERE "users"."hidden_at" IS NULL AND "users"."id" = $1 LIMIT 1  [["id", 1]]
 => #<User id: 1, email: ...> 
2.3.2 :002 > a.poll_officer
  Poll::Officer Load (107.0ms)  SELECT  "poll_officers".* FROM "poll_officers" WHERE "poll_officers"."user_id" = $1 LIMIT 1  [["user_id", 1]]
 => nil 
2.3.2 :003 > 

So, maybe this would fix it:

    def load_officer_assignment
      @officer_assignments = current_user.poll_officer.
                               officer_assignments.
                               voting_days.
                               where(date: Date.current) if current_user.poll_officer.present?
    end

Would that interfere with further validations? So far, the suggested fix gives the desired behavior, as shown. And not breaking any tests either.

captura de pantalla_2017-09-15_11-52-06

I sent a PR for this issue on https://github.com/consul/consul/pull/1872

Was this page helpful?
0 / 5 - 0 ratings