I am trying to use <%= f.email_field :email, value: current_user.email %>
in an html.erb file. Why do I get the error
undefined method `email' for nil:NilClass
Could it be because I'm in a different controller? Please let me know.
That error is stating that current_user
is nil - that is, no user is currently logged in.
If you want your view to work when no one is logged in, you could use current_user.try(:email)
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.