Rails - why I'm getting undefined method `name' for nil:NilClass


I'm displaying question by categories and each question has its own
number. I made it like this(index.html.erb):



<% @categories.each do |category| %>
<div id=<%= "box#{category.id}" -%>>
<h1><%= category.name %></h1>
<% category.questions.each_with_index do |question, i|
%>
<ul class="question-list" style="display: inline;">
<li><%= link_to (i + 1), show_path
%></li>
</ul>
<% end %>
</div>
<% end %>


And when I click on question number I would like to show it like
this(show.html.erb):



<div class="question-wrapper">
<h1><%= @category.name %></h1>
<div class="image left-align">
<%= question_image_tag(question, :large) %>
</div>
<div class="question-text right-align">
<%= @question.question_name %>
</div>
<p><%= @question.answer %></p>
</div>


This is my controller:



def index
@categories = Category.all
@questions = Question.all
end

def show
@categories = Category.all
@questions = Question.all
end


Now, I'm getting undefined method `name' for nil:NilClass (also
throws error for all methods in show.html.erb) and I can't resolve
it.



Question: What should I do to resolve undefined method
`name' for nil:NilClass?


- Technology - Languages
+ Webmasters
+ Development
+ Development Tools
+ Internet
+ Mobile Programming
+ Linux
+ Unix
+ Apple
+ Ubuntu
+ Mobile & Tablets
+ Databases
+ Android
+ Network & Servers
+ Operating Systems
+ Coding
+ Design Software
+ Web Development
+ Game Development
+ Access
+ Excel
+ Web Design
+ Web Hosting
+ Web Site Reviews
+ Domain Name
+ Information Security
+ Software
+ Computers
+ Electronics
+ Hardware
+ Windows
+ PHP
+ ASP/ASP.Net
+ C/C++/C#
+ VB/VB.Net
+ JAVA
+ Javascript
+ Programming
Privacy Policy - Copyrights Notice - Feedback - Report Violation 2018 © BigHow