jeudi 24 décembre 2015

undefined method `email' for nil:NilClass link.user.email

In my index.html.erb file, I am getting an undefined method for email. I went into the rails console and tried running User.first.email and it worked perfectly. I tried taking out email and running link.user and that also worked. I am not sure why email is coming across as undefined when there is a user tied to a link and a user has an email. I am looking for some suggestions as to what may be going wrong.

Index.html.erb

<%= link.user.email %>

Schema with migrations already run

create_table "users", force: :cascade do |t|
    t.string   "email",                  default: "", null: false

Aucun commentaire:

Enregistrer un commentaire