Home NoMethodError - undefined method `status' for nil:NilClass
Reply: 0

NoMethodError - undefined method `status' for nil:NilClass

user1261
1#
user1261 Published in April 27, 2018, 8:07 am

I am trying to work through my table and pull out and list each of the status types under their own heading. When I run this I get NoMethodError for Tickets#index with the error reading undefined method `status' for nil:NilClass

index.html.erb

<h2>New<h2>
<% if @ticket.status == 'New' %>
    <% tickets.each do |ticket| %>
                    <p><%= link_to ticket_path(ticket) do %>
                        <strong><%= ticket.category %></strong>
                    <% end %></p>
                    <p><%= ticket.requestor_name %></p>
                    <p><%= ticket.requestor_lab %></p>
                    <p><%= ticket.contact %></p>
                    <p><%= ticket.requested_by %></p>
                    <%= ticket.status %>
    <% end %>
<% end %>

The code basically repeats for the other status types.

Controller:

 def index
    @tickets = Ticket.all

    if params[:filter_by]
        @tickets = Ticket.where(:category => params[:filter_by])
    else
        @tickets = Ticket.all
    end
end
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.364952 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO