Search code examples
ruby-on-railsdevise

ActionView::Template::Error (undefined method `email' for #<User id: nil, name: nil, created_at: nil, updated_at: nil>): on Heroku


Hello and Thanks for anyone who can help me i'm desperate So I'm not sure what it is. On local host all works fine.

I have got this error in Heroku.

2022-10-28T02:39:55.334817+00:00 heroku[router]: ... ActionView::Template::Error (undefined method `email' for #\<User id: nil, name: nil, created_at: nil, updated_at: nil\>):
2022-10-28T02:40:20.465661+00:00 app\[web.1\]: \[0601e31b-0cf4-4714-a8ef-e41257302a21\]     11:
2022-10-28T02:40:20.465661+00:00 app\[web.1\]: \[0601e31b-0cf4-4714-a8ef-e41257302a21\]     12:   \<div class="field"\>
2022-10-28T02:40:20.465662+00:00 app\[web.1\]: \[0601e31b-0cf4-4714-a8ef-e41257302a21\]     13:     \<%= f.label :email %\>

2022-10-28T02:40:20.465662+00:00 app\[web.1\]: \[0601e31b-0cf4-4714-a8ef-e41257302a21\]     14:     \<%= f.email_field :email, autofocus: true, autocomplete: "email" %\>
2022-10-28T02:40:20.465663+00:00 app\[web.1\]: \[0601e31b-0cf4-4714-a8ef-e41257302a21\]     15:   \</div\>
2022-10-28T02:40:20.465663+00:00 app\[web.1\]: \[0601e31b-0cf4-4714-a8ef-e41257302a21\]     16:
2022-10-28T02:40:20.465663+00:00 app\[web.1\]: \[0601e31b-0cf4-4714-a8ef-e41257302a21\]     17:   \<div class="field"\>
2022-10-28T02:40:20.465664+00:00 app\[web.1\]: \[0601e31b-0cf4-4714-a8ef-e41257302a21\]  
2022-10-28T02:40:20.465664+00:00 app\[web.1\]: \[0601e31b-0cf4-4714-a8ef-e41257302a21\] app/views/devise/registrations/new.html.erb:14
2022-10-28T02:40:20.465664+00:00 app\[web.1\]: \[0601e31b-0cf4-4714-a8ef-e41257302a21\] app/views/devise/registrations/new.html.erb:3

the problem seens to be on devise but i cannot find where

this is my aplication.html.erb where i think the problem could be``

`

\<!DOCTYPE html\>
\<html\>
\<head\>
\<title\>BudgetApp\</title\>
\<%= csrf_meta_tags %\>

    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>

\</head\>

\<body\>

    <%= yield %>

\</body\>
\</html\>

`

and this is the render from devise where the problem seens to start

<h2 class="log-in-text"\>Log in User\</h2\>

\<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %\>
\<div class="field"\>
\<%= f.label :email %\>\<br /\>
\<%= f.email_field :email, autofocus: true, autocomplete: "email" %\>
\</div\>

\<div class="field"\>
\<%= f.label :password %\>\<br /\>
\<%= f.password_field :password, autocomplete: "current-password" %\>
\</div\>

\<% if devise_mapping.rememberable? %\>
\<div class="field"\>
\<%= f.check_box :remember_me %\>
\<%= f.label :remember_me %\>
\</div\>
\<% end %\>

\<div class="actions"\>
\<%= f.submit "Log in", :class =\> 'btn-form' %\>

\</div\>

\<% end %\>
\<div class="links-shared"\>
\<%= render "devise/shared/links" %\>
\</div\>

i will apreciate help. https://infinite-forest-50155.herokuapp.com this is the app. y press the log out button but in the log there are no errors, but when I click on sign in or log in the same error appears

I try to Look for related Issues on stackoverflow but any error seems to be related to mine. y modify the enviroment on the local project to see if works. my local project works perfectly so I dont know what to do.


Solution

  • The problem was the database migrations. I created the create user DB and after I made a remove a column from that DB, but when I uploaded the migration to Heroku, it only migrated the creations and not the remove so that caused a problem in the DB.