Reputation: 11
I am learning ruby on rails. I want to make editable users account.
I have an error in localhost:
undefined method `model_name' for NilClass:Class
This is my edit.html.erb file:
<h1>Edit user</h1>
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages', :object => f.object %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password %>
</div>
<div class="field">
<%= f.label :password_confirmation, "Confirmation" %><br />
<%= f.password_field :password_confirmation %>
</div>
<div class="actions">
<%= f.submit "Update" %>
</div>
<% end %>
<div>
<%= gravatar_for @user %>
<a href="http://gravatar.com/emails">change</a>
</div>
Can you provide a solution?
Upvotes: 1
Views: 235
Reputation: 11375
Most likely your @user object is nil, so when it tries to call @user.model_name, it fails. You should check your controller logic for loading it, and make sure it finds a valid @user.
Upvotes: 1