Method returns me as null value

0

When I create my code below, it returns me this error message, saying that my method is undefined for nil (undefined method 'errors' for nil:NilClass)

Code:

<ul>
  <% @task.errors.full_messages.each do |message| %>
    <li><%= message %></li> 
  <%end%>
</ul>

<%=form_for @task do |f|%>
    <%=f.label :description, 'Descrição'%>
    <%=f.text_field :description%>
    <%=f.label :status, 'Status'%>
    <%=f.check_box :status%>
    <%=f.submit 'Criar'%>
<%end%>
    
asked by anonymous 15.10.2018 / 16:21

1 answer

0

In the controller, you must have an action pointing to this view. There in action, @task needs to be instantiated. See:

def new
  @task = Task.new
end
    
16.10.2018 / 03:39